0

# Why will a piece of text not change if a value linked to it via script changes?

2Loos 145
5 months ago

What I would like to know: A. Why this happens B. Ways to fix it C. Is there anything I should remember about changing text using constantly changing values

My Script:

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local clonedgui1 = game.ServerStorage.Deaths:Clone()
clonedgui1.TextLabel.TextColor3 = Color3.fromRGB(255,0,0)
clonedgui1.TextLabel.Text = "Deaths: "..deaths

local clonedgui2 = game.ServerStorage.Kills:Clone()
clonedgui2.TextLabel.TextColor3 = Color3.fromRGB(0,255,0)
clonedgui2.TextLabel.Text = "Kills: "..kills

end)

end)



If you are wondering what this script is doing, I made a GUI that floats above a player's head showing their Kills and Deaths. Obviously, the value is changing a lot, and I am clueless as to why the text won't change. I have tried using the following code inside the script:

killsVal.Changed:Connect(function(NewValue)
killsVal.Value = kills
end)
deathsVal.Changed:Connect(function(NewValue)
deathsVal.Value = deaths
end)

local function onValueChanged()
if kills.Value ~= killsVal then
kills.Value = killsVal
end
if deaths.Value ~= deathsVal then
deaths.Value = deathsVal
end
end


but was only lead to a bunch of errors including this "leaderstats is not a valid member of Player." I would be grateful for any help.

0

You are only changing the text label text once, which is when the character is added. You need to make it so your text changes whenever the value changes, for instance...

killsVal.Changed:Connect(function(NewValue)
killsVal.Value = kills
end)
deathsVal.Changed:Connect(function(NewValue)
deathsVal.Value = deaths
end)

local function onValueChanged()
if kills.Value ~= killsVal then
kills.Value = killsVal
clonedgui2.Textlabel.Text = "Kills: "..kills
end
if deaths.Value ~= deathsVal then
deaths.Value = deathsVal
clonedgui1.Textlabel.Text = "Deaths: "..deaths
end
end

0
2Loos 145
5 months ago

I'm confused about this... I created a local function but it doesn't even bother to start up, and I don't know how to make it run. Excuse my blunt terminology, I am a beginner scripter.

local function StatChange(player)

local kills = stats.Kills.Value
local deaths = stats.Deaths.Value
local killsVal = stats.Kills
local deathsVal = stats.Deaths

kills.Changed:Connect(function()
killsVal.Value = kills
clonedgui2.Text = killsVal.Value
end)

deaths.Changed:Connect(function()
deathsVal.Value = deaths
clonedgui1.Text = deathsVal.Value
end)

end