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

Humanoid.Died event only able to occur once?

Asked by 5 years ago
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

function lives()
    game.Workspace.Lives.Value = game.Workspace.Lives.Value - 1
    print(game.Workspace.Lives.Value)
end

char:WaitForChild("Humanoid").Died:connect(lives)

The code above works perfectly... once. After that, it no longer functions. I'm confused as to why this is happening and the API reference on RobloxDev haven't clued me in on the issue. Any ideas?

0
Use player.CharacterAdded Griffi0n 315 — 5y

1 answer

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
5 years ago

Use player.CharacterAdded

local player = game:GetService("Players").LocalPlayer

local function onDeath()
    workspace.Lives.Value = workspace.Lives.Value - 1
    print(workspace.Lives.Value)
end
local function onCharacterAdded(character)
    character.Humanoid.Died:Connect(onDeath)
end

player.CharacterAdded:Connect(onCharacterAdded)
0
you should wait for the humanoid... brokenVectors 525 — 5y
Ad

Answer this question