Why will a piece of text not change if a value linked to it via script changes?
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:
01 | local ServerStorage = game:GetService( "ServerStorage" ) |
02 | local Players = game:GetService( "Players" ) |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | local kills = game.Players [ player.Name ] .leaderstats.Kills.Value |
07 | local deaths = game.Players [ player.Name ] .leaderstats.Deaths.Value |
08 | local killsVal = game.Players [ player.Name ] .leaderstats.Kills |
09 | local deathsVal = game.Players [ player.Name ] .leaderstats.Deaths |
16 | player.CharacterAdded:Connect( function (character) |
18 | local clonedgui 1 = game.ServerStorage.Deaths:Clone() |
19 | clonedgui 1. TextLabel.TextColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
20 | clonedgui 1. Parent = game.Workspace:WaitForChild(player.Name).Head |
21 | clonedgui 1. TextLabel.Text = "Deaths: " ..deaths |
26 | local clonedgui 2 = game.ServerStorage.Kills:Clone() |
27 | clonedgui 2. TextLabel.TextColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
28 | clonedgui 2. Parent = game.Workspace:WaitForChild(player.Name).Head |
29 | clonedgui 2. TextLabel.Text = "Kills: " ..kills |
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:
01 | killsVal.Changed:Connect( function (NewValue) |
02 | killsVal.Value = kills |
04 | deathsVal.Changed:Connect( function (NewValue) |
05 | deathsVal.Value = deaths |
08 | local function onValueChanged() |
09 | if kills.Value ~ = killsVal then |
10 | kills.Value = killsVal |
12 | if deaths.Value ~ = deathsVal then |
13 | deaths.Value = deathsVal |
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.