✓ Accepted answer
When you use . to get a child, you get an error if that object does not exist -- you do not get nil.
If you aren't sure an object exists, you should use :FindFirstChild(name) instead.
If you just want to wait for an object to exist, you can use :WaitForChild. A caveat is that it will not stop waiting if the object is inserted before being given the proper name (i.e., you can't use leaderstats = Instance.new("IntValue", player) because it will have the name "IntValue" when added to the player)
It makes more sense to only get the player and kos once.
It's a good idea to use the actual spelling for a word. You don't get anything by shortening player by 2 letters, other than making it less readable and harder to type.
Your script only uses it two times, there's no reason to save 4 bytes!
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local kos = leaderstats:WaitForChild("KOs")
while wait(1) do
script.Parent.Text = "KOs: " .. kos.Value
end
1 comment
Thanks!