Buttons and Points
Buttons and Points
Problem
You want to create a button that when you touch it, you earn points.
Solution
Create a leaderboard, and edit the point values when Touched event fires.
local enabled = true game.Players.PlayerAdded:connect(function(player) local leader, score = Instance.new('IntValue'), Instance.new('IntValue') leader.Name = 'leaderstats' score.Name = 'Score' score.Parent = leader leader.Parent = player end) Workspace.Button.Touched:connect(function(hit) local p = game.Players:FindFirstChild(hit.Parent.Name) if pl and enabled == true then enabled = false p.leaderstats.Score.Value = p.leaderstats.Score.Value + 5 wait(20) enabled = true end end)
Discussion
We first include a leaderboard to manage points that players get. Then we listen for the Touched
event on some button in the Workspace. We check to see if it’s a valid Player that hit the button and we also use debounce to prevent the button from giving out too many points. Then we set leaderstats.Score.Value
the value of that Score
IntValue to be its own value plus 5.