This is what I have to make the script detect the players health constantly. But I dont know how to make it work over and over
local player = game.Players.LocalPlayer local workplayer = game.Workspace:WaitForChild(player.Name) local humanoid = workplayer.Humanoid local remote = game.ReplicatedStorage.Playerhealth0 repeat wait() until humanoid.Health <= 0 remote:FireServer()
local player = game.Players.LocalPlayer local workplayer = player.Character or player.CharacterAdded:Wait() local humanoid = workplayer:WaitForChild("Humanoid") local remote = game.ReplicatedStorage:WaitForChild("Playerhealth0") humanoid.Died:Connect(function() remote:FireServer() end)
Instead of using a loop, use the humanoid.Died
event.
Place this in StarterCharacterScripts
under the StarterPlayer folder.
repeat wait() until game.Players.LocalPlayer repeat wait until game.Players.LocalPlayer.Character:IsDescendantOf(workspace) ---------------------------------------------------------------------------------------------------------- local player = game.Players.LocalPlayer local workplayer = game.Workspace:WaitForChild(player.Name) local humanoid = workplayer.Humanoid local remote = game.ReplicatedStorage:WaitForChild('Playerhealth0') function ON_DEATH() remote:FireServer() print(player.Name .. " died") end humanoid.Died:connect(ON_DEATH)