|
I am trying to make a gui button that will give a player money when clicked. This is the code I have:
Cash Stat Script:
game.Players.PlayerAdded:connect(function(player)
stat = Instance.new("IntValue")
stat.Name = "leaderstats"
stat.Parent = player
cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = stat
end)
Give player money button:
moneyToGive = 5
debounce = false
function onClicked(playerWhoClicked)
if debounce == true then return end
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player == nil then return end
stat = player:findFirstChild("leaderstats")
if stat == nil then return end
cash = stat:findFirstChild("Cash")
if cash == nil then return end
debounce = true
cash.Value = cash.Value + moneyToGive
wait(300)
debounce = false
end
It also doesn't show the loading so that the player has to wait before getting money:
local Gui = game.Lighting.GUI --Replace this with the location of your GUI
function GiveGui(Player)
if Player.PlayerGui:FindFirstChild(Gui.Name)~=nil then return end
Gui:Clone().Parent=Player.PlayerGui
end
script.Parent.Touched:connect(function(hit)
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
if Player==nil then return end
GiveGui(Player)
end) |
|
|
Come on. 12 people viewed yet no one said a thing. I would like to finish this soon. |
|
|
|
Maybe you'll get help if you post a script you made. |
|
|
Are you trying to say it's a bad thing? I've been editing these from the sources I found them at for hours, and no matter what I try it doesn't work. I thought the roblox community where supposed to help. I just am trying to finish this script and the best thing your doing for me is bring my post up higher. Don't comment unless your helping. |
|
|
Maybe if you tell us the directory of the button, we might be able to make one for you. |
|
|
I have it under StarterGui. Its a screen gui with a Textbutton on the side with 2 scripts. one for a job loading sequence I guess you could say, and another one that gives the play the money. These scripts work on a brick, but not on a button even though I change it to OnClick. |
|
|
Put this in the button
script.Parent.MouseButton1Down:connect(function()
local player = game.Players.LocalPlayer
local stats = player.leaderstats
local cash = stats.Cash
money = 5
cash.Value = cash.Value + money
end) |
|
|
Thank you so much! Now I just have one last question, would it work if I added wait() in to that code so that the play can't spam his money? I just tried to but it just made the timing for it off by a lot. Also, this may be pushing it but that loading code I had didn't really work on the button either. If it isn't a pain could I maybe have some help with that to? |
|
|
Your script amazing! But it can be spammed and keeps giving the player money but I can't figure out how to get the wait function to work. Could you maybe add this real quick? |
|
|
bump, Sorry for double bumping! |
|
|
I know C++, C, JavaScript, HTML, CSS, NOT LUA
But you could try and add a wait(.5) or something, maybe then it cant get spammed. |
|
|
I tried that, all it does is wait 5 seconds, and still allow player stop be spammed. I want it so that the player can click it, then have to wait a minute before clicking it again. |
|
|
I figured it out! I did a little bit of digging and found a free model that adds money to there cash every 5 minutes. |
|
|
ew a free model?
why not just use Os Time? |
|
|
ew, a free model?
why not just use the internal clock such as os time? |
|
|
|
how many parents does the script have until it gets to StarterGui? |
|
|
NVM
debounce = false
script.Parent.MouseButton1Down:connect(function()
if debounce == false then
debounce = true
local player = game.Players.LocalPlayer
local stats = player.leaderstats
local cash = stats.Cash
money = 5
cash.Value = cash.Value + money
wait(.5)
debounce == false
end) |
|
|
These post are way to late. I already released the game I was working on in the time you replied.
SELF ADVERTISMENT!
www.roblox.com/Forum/ShowPost.aspx?PostID=155318221 |
|
|
|
ewww 10 year old judging a book by its covered |
|