Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

This deaths counter won't work??? I need help!!!!!!!!!

Asked by 5 years ago
Edited 5 years ago

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.

0
By the way, you should always use names that make it easy to understand what you are working with. User#21908 42 — 5y
0
If I say ? how is anyone supposed to have any idea that I am talking about deaths. User#21908 42 — 5y
0
Especially if other people are going to be reading your code. User#21908 42 — 5y
0
FilterScript Enabled? ToddyWars 41 — 5y
View all comments (2 more)
0
I said: "EDIT: The "?" is a skull-and-crossbones symbol." GamingZacharyC 152 — 5y
0
it is just not showing up in ScriptingHelpers GamingZacharyC 152 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

The problem lies in the fact that you wrongly assume that the 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)
0
this does not work still. GamingZacharyC 152 — 5y
0
How so? User#19524 175 — 5y
0
it won't add the death to the IntValue. GamingZacharyC 152 — 5y
0
I put after "(function()" "print("Player Died")". here is my output: player died player died player died player died player died player died GamingZacharyC 152 — 5y
Ad

Answer this question