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

Update number in text button stats gui helpp ??

Asked by 5 years ago
Edited by Azarth 5 years ago

I'm doing my stats gui, most every time a number is added I have to reset the character to change how do I change the gui the moment I click?

Script at the numbers:


local player = game.Players.LocalPlayer local userId = player.UserId local Data = player:WaitForChild("Data") local Stats = script.Parent local SkillPoints = Stats:WaitForChild("SkillPoints") local Defense = Stats:WaitForChild("Defense") local Health = Stats:WaitForChild("Health") local MaxMana = Stats:WaitForChild("MaxMana") local ManaDamage = Stats:WaitForChild("ManaDamage") local MaxStamina = Stats:WaitForChild("MaxStamina") local Strength = Stats:WaitForChild("Strength") local Speed = Stats:WaitForChild("Speed") Defense.Text = ""..Data.Defense.value Health.Text = ""..Data.Health.value MaxMana.Text = ""..Data.MaxMana.value ManaDamage.Text = ""..Data.ManaDamage.value MaxStamina.Text = ""..Data.MaxStamina.value Strength.Text = ""..Data.Strength.value Speed.Text = ""..Data.Speed.value SkillPoints.Text = ""..Data.SkillPoints.Value` --Script upgrade stats: local player = game.Players.LocalPlayer local Data = player:WaitForChild("Data") local Button = script.Parent function onClick() Data.Speed.Value = Data.Speed.Value + 1 Data.SkillPoints.Value = Data.SkillPoints.Value - 1 script.Sound:Play() end Button.MouseButton1Click:connect(onClick)
0
Next time, hi-light all your code and click that big blue Lua icon, instead of the inline code option. Azarth 3141 — 5y
0
Ok, Thanks Diguinho4321 -8 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Im sure theres a more efficient way to do this, and an easier way(just a basic while loop), but this is how i'd go about it.

local player = game.Players.LocalPlayer
local userId = player.UserId

local Data = player:WaitForChild("Data")

local Stats = script.Parent
local SkillPoints = Stats:WaitForChild("SkillPoints")
local Defense = Stats:WaitForChild("Defense")
local Health = Stats:WaitForChild("Health")
local MaxMana = Stats:WaitForChild("MaxMana")
local ManaDamage = Stats:WaitForChild("ManaDamage")
local MaxStamina = Stats:WaitForChild("MaxStamina")
local Strength = Stats:WaitForChild("Strength")
local Speed = Stats:WaitForChild("Speed")

Defense.Changed:Connect(function()
    Defense.Text = ""..Data.Defense.Value
end)

Health.Changed:Connect(function()
    Health.Text = ""..Data.Health.Value
end)

MaxMana.Changed:Connect(function()
    MaxMana.Text = ""..Data.MaxMana.Value
end)

ManaDamage.Changed:Connect(function()
    ManaDamage.Text = ""..Data.ManaDamage.Value
end)

MaxStamina.Changed:Connect(function()
    MaxStamina.Text = ""..Data.MaxStamina.Value
end)

Strength.Changed:Connect(function()
    Strength.Text = ""..Data.Strength.Value
end)

Speed.Changed:Connect(function()
    Speed.Text = ""..Data.Speed.Value
end)

SkillPoints.Changed:Connect(function()
    SkillPoints.Text = ""..Data.SkillPoints.Value
end)

--Script upgrade stats:

--local player = game.Players.LocalPlayer ----- Don't define player twice
local Data = player:WaitForChild("Data")

local Button = script.Parent

function onClick()
    Data.Speed.Value = Data.Speed.Value + 1
    Data.SkillPoints.Value = Data.SkillPoints.Value - 1
    script.Sound:Play()
end

Button.MouseButton1Click:Connect(onClick) -- Connect not connect
0
Thanks, I'll test. Diguinho4321 -8 — 5y
0
It did not work: /, I still have to reset the character to change Diguinho4321 -8 — 5y
0
Is it any specific values that arent working? Speed/Skillpoints are those changing correctly? DinozCreates 1070 — 5y
0
everything is changing, but it only changes when I restart the character Diguinho4321 -8 — 5y
Ad

Answer this question