Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Give gold onClicked?

Asked by
nicros 165
9 years ago

so im wanting to add a simple "finish" system in my game and im very noob at Lua, just started using it a few days ago :P

so i figured an easy way to do a fishing system would be have a brick in the water, they click it and it does an animation which im not worried about atm and every little bit it adds gold to their gold.

i thought this would be easy for me to add but i guess not, this is what i came up with, and like i said i JUST started Lua so dont be mean if this is a stupid attempt at writing this out

Leaderstats = game.Players.Player:FindFirstChild("Leaderstats")

local Enabled = false
function onClicked()
    if Enabled == false then
        Enabled = true
    end
    if Enabled == true then
        Leaderstats.Gold.Value = Leaderstats.Gold.Value + 10
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

i guess my question is, how do i change this to actually add gold to my leaderstats when i click the brick, i can figure out how to have to repeat giving gold every little bit. THANKS in advance :)

0
Enabled value is useless as you're setting it to be always true anyway Ryzox 220 — 9y
0
thanks for clearing that up :p, saw other scripts similar to this use it so i thought it was something you do >> nicros 165 — 9y

1 answer

Log in to vote
2
Answered by
Ryzox 220 Moderation Voter
9 years ago
script.Parent.ClickDetector.MouseClick:connect(function(player) -- Mouse click returns the player who clicked :)
    local Leaderstats = player:findFirstChild("leaderstats") -- declaring leaderstats
    if Leaderstats:findFirstChild("Gold") then -- Just double checking the value is there so that scripts don't break :)
            Leaderstats.Gold.Value = Leaderstats.Gold.Value + 10 -- adds 10 to the value (make sure it's intvalue or numbervalue)
    end
end)

0
:) wow, thanks for the help and awesome details on what it all does. nicros 165 — 9y
Ad

Answer this question