Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Give gold onClicked?

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 :)

2 comments

0

Enabled value is useless as you're setting it to be always true anyway

0

thanks for clearing that up :p, saw other scripts similar to this use it so i thought it was something you do >>

1 answer

✓ Accepted answer
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)

1 comment

0

:) wow, thanks for the help and awesome details on what it all does.

This discussion is preserved as it was. New answers, comments, and votes are closed.