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