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:
1 | game.Players.PlayerAdded:Connect( function (plr) |
2 | local leaderstats = Instance.new( "Folder" , plr) |
3 | leaderstats.Name = "leaderstats" |
4 | local deaths = Instance.new( "IntValue" , leaderstats) |
5 | deaths.Name = "?" |
6 | end ) |
In StarterCharacterScripts:
1 | script.Parent.Humanoid.Died:Connect( function () |
2 | local plr = game.Players:GetPlayerFromCharacter(script.Parent) |
3 | plr:LoadCharacter() |
4 | local deaths = plr.leaderstats:FindFirstChild( "?" ).Value |
5 | deaths = deaths + 1 |
6 | print (deaths) -- it won't even print the value of ? |
7 | 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.1 | script.Parent.Humanoid.Died:Connect( function () |
2 | local plr = game.Players:GetPlayerFromCharacter(script.Parent) |
3 | plr:LoadCharacter() |
4 | local deaths = plr.leaderstats:FindFirstChild( "?" ) -- set to object |
5 | deaths.Value = deaths.Value + 1 -- it works |
6 | print (deaths.Value) -- print the value of ? |
7 | end ) |