I am making a script for my friends obby. It instantly loads the player's character and adds a death (?) to their ? leaderstat. It wont work though.
In the ServerScriptService:
game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder", plr) leaderstats.Name = "leaderstats" local deaths = Instance.new("IntValue", leaderstats) deaths.Name = "?" end)
In StarterCharacterScripts:
script.Parent.Humanoid.Died:Connect(function() local plr = game.Players:GetPlayerFromCharacter(script.Parent) plr:LoadCharacter() local deaths = plr.leaderstats:FindFirstChild("?").Value deaths = deaths + 1 print(deaths) -- it won't even print the value of ? end)
EDIT: The "?" is a skull-and-crossbones symbol.
deaths
variable is a reference to the actual property of IntValue
. If the Value
of the IntValue
changes, the variables you have defined won't update; only its Value
property will change. In order to fix this, you can remove the deaths
variable and only make direct accesses to the Value
property of the IntValue
. You could also modify the variables to hold the IntValue
object itself.script.Parent.Humanoid.Died:Connect(function() local plr = game.Players:GetPlayerFromCharacter(script.Parent) plr:LoadCharacter() local deaths = plr.leaderstats:FindFirstChild("?")-- set to object deaths.Value = deaths.Value + 1 -- it works print(deaths.Value) -- print the value of ? end)