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

Humanoid.Died event only able to occur once?

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?

1 comment

0

Use player.CharacterAdded

1 answer

✓ Accepted answer

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)

1 comment

0

you should wait for the humanoid...

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