Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

6 comments

0

By the way, you should always use names that make it easy to understand what you are working with.

0

If I say ? how is anyone supposed to have any idea that I am talking about deaths.

0

Especially if other people are going to be reading your code.

0

FilterScript Enabled?

0

I said: "EDIT: The "?" is a skull-and-crossbones symbol."

0

it is just not showing up in ScriptingHelpers

1 answer

###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)

4 comments

0

this does not work still.

0

How so?

0

it won't add the death to the IntValue.

0

I put after "(function()" "print("Player Died")". here is my output: player died player died player died player died player died player died

This discussion is preserved as it was. New answers, comments, and votes are closed.