How to add 5 to someones leaderstat using clickdetector?

How can I add 5 units to a players leaderstat value names “Potatoes” when they click a button?

Script:

local cstage = script.Parent

cstage.ClickDetector.MouseClick:Connect(function(cplr)
	local mod = game.ServerStorage["EmptyPlot"]
	local clone = mod:Clone()
	clone.Parent = workspace

	local empty = script.Parent
	empty.Parent = game.ServerStorage
	
	
end)
3 Likes

Locate the player’s leaderstats folder, then locate the ‘Potatoes’ leaderstat and increment its ‘Value’ property by a value of 5.

1 Like
local cstage = script.Parent

cstage.ClickDetector.MouseClick:Connect(function(cplr)
	cplr.leaderstats.Potatoes.Value += 5	
end)

That script will add 5 to their potatoes amount. Did you make a leaderstats script yet, by the way?

Yeah, this is the script from ServerScriptService:

game.Players.PlayerAdded:Connect(function(Player)
	local Stat = Instance.new("IntValue")
	Stat.Name = "leaderstats"

	local Score = Instance.new("IntValue")
	Score.Name = "Potatoes"
	Score.Value = 0

	Score.Parent = Stat
	Stat.Parent = Player
end)
game.Players.PlayerAdded:Connect(function(Player)
	local Stat = Instance.new("IntValue")
	Stat.Name = "leaderstats"
    Stat.Parent = Player

	local Score = Instance.new("IntValue")
	Score.Name = "Potatoes"
	Score.Value = 0
	Score.Parent = Stat

end)
local cstage = script.Parent
local storage = game:GetService("ServerStorage")

cstage.ClickDetector.MouseClick:Connect(function(cplr)
	local mod = storage["EmptyPlot"]
	local clone = mod:Clone()
	clone.Parent = workspace

	local empty = script.Parent
	empty.Parent = storage 
	--put this part where you want to award the player.
	cplr.leaderstats.Potatoes.Value += 5	
end)

Awesome, my script should work fine then.

Yes, if you were to combine it. If not you would delete everything inside that function besides the awarding potatoes.

1 Like