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

[?]Died Event


function oa(object)
local player = game.Players:playerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace.StageSpawn:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end

The Script almost works fine but the died event bit. In the died event every time a player dies I want the Death "IntValue" to add 1 to the Death value to the player who died.

function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = object
local death = Instance.new("IntValue")
death.Name = "Death"
death.Value = 0
death.Parent = ack 
game:GetService('Players').PlayerAdded:connect(function(player) 	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function(Gamer)--Here the Died event
			game.Players.Gamer.leaderstats.Death.Value = 0+1 --I don't know why this doesn't work for some reason. 
		end)
	end)
end)
end end

game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)


1 answer

You're trying to index the player with a nil parameter from the Died Event. The Died Event doesn't return anything, so 'Gamer' is nil, and even if the Died Event did return anything you're indexing it incorrectly, it's have to be like: game.Players[Gamer].

You already have a variable for the player, the parameter from your PlayerAdded Event.

Also, you don't increase the stat by one like '.leaderstats.Death.Value = 0+1', it would just always be one after they died. You have to add 1 relative to the current value of 'Death'.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid")
		character.Humanoid.Died:connect(function()
			player.leaderstats.Death.Value = player.leaderstats.Death.Value + 1
		end)
	end)
end)

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