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

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

Asked by 6 years ago
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)
0
Any attempt on this? And also the parent argument of Instance.new is deprecated. User#19524 175 — 6y
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 supermariodeadtolive 55 — 6y
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? masterblokz 58 — 6y

2 answers

Log in to vote
1
Answered by
CjayPlyz 643 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
Works! ZapherosX 43 — 6y
0
Np :) CjayPlyz 643 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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)

?

Answer this question