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

[?]Died Event

Asked by 9 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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

Answer this question