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

Update number in text button stats gui helpp ??

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)

2 comments

0

Next time, hi-light all your code and click that big blue Lua icon, instead of the inline code option.

0

Ok, Thanks

1 answer

✓ Accepted answer

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

4 comments

0

Thanks, I'll test.

0

It did not work: /, I still have to reset the character to change

0

Is it any specific values that arent working? Speed/Skillpoints are those changing correctly?

0

everything is changing, but it only changes when I restart the character

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