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

How would I make a button that gives a +1 on each stat?

game.Players.PlayerAdded:connect(function(player)
	player.characteradded:Connect(function(char)
		local data = Instance.new("Folder", player)
		data.Name = "Stats"
		
		local Strength = Instance.new("IntValue", data)
		Strength.Name = "Strength"
		Strength.Value = 0
		
		local Defense = Instance.new("IntValue", data)
		Defense.Name = "Defense"
		Defense.Value = 0
		
		local Agility = Instance.new("IntValue", data)
		Agility.Name = "Agility"
		Agility.Value = 0
		
		local Skill = Instance.new("IntValue", data)
		Skill.Name = "Skill"
		Skill.Value = 0
	end)
end)

3 comments

0

Any attempt on this? And also the parent argument of Instance.new is deprecated.

0

for the parent value, try this: local Strength = Instance.new("IntValue") Strength.Parent = data Strength.Name = "Strength" Strength.Value = 0 the +1 is this: Strength.Value = Strength.Value + 1

0

The whole point of not using the parent argument is setting the properties before the parent, such as Name and Value, is it not?

2 answers

✓ Accepted answer

For this to work put a click detector inside the button.

local button = script.Parent -- replace with the location of the button

button.ClickDetector.MouseClick:Connect(function(player)
	player.Stats.Strength.Value = player.Stats.Strength.Value + 1
	player.Stats.Defense.Value = player.Stats.Defense.Value + 1
	player.Stats.Agility.Value = player.Stats.Agility.Value + 1
	player.Stats.Skill.Value = player.Stats.Skill.Value + 1
end)

if it doesn't work tell me.

2 comments

0

Works!

0

Np :)

wait()
local button = script.Parent
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("stats")
button.MouseButton1Click:Connect(function()
	stats.Strength.Value = stats.Strength.Value + 1
	stats.Defense.Value = stats.Defe.Value + 1
	stats.Agility.Value = stats.Agility.Value + 1
	stats.Skill.Value = stats.Skill.Value + 1
end)

?

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