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")
game.Players.PlayerAdded:Connect(function(player)
local kills = game.Players[player.Name].leaderstats.Kills.Value
local deaths = game.Players[player.Name].leaderstats.Deaths.Value
local killsVal = game.Players[player.Name].leaderstats.Kills
local deathsVal = game.Players[player.Name].leaderstats.Deaths
player.CharacterAdded:Connect(function(character)
local clonedgui1 = game.ServerStorage.Deaths:Clone()
clonedgui1.TextLabel.TextColor3 = Color3.fromRGB(255,0,0)
clonedgui1.Parent = game.Workspace:WaitForChild(player.Name).Head
clonedgui1.TextLabel.Text = "Deaths: "..deaths
local clonedgui2 = game.ServerStorage.Kills:Clone()
clonedgui2.TextLabel.TextColor3 = Color3.fromRGB(0,255,0)
clonedgui2.Parent = game.Workspace:WaitForChild(player.Name).Head
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.
