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

Why won't this respawn script work?

I want this to happen each time the player health is 0

local player = game.Players
local players = player.LocalPlayer
local char = player.Character
humanoid = char:FindFirstChild("Humanoid")
function loadcharacter(respawn)
if humanoid.Health > 1 then
player:GetPlayerFromCharacter(respawn):LoadCharacter()
end
end

Error: Character is not a valid member of Players Help?

2 answers

On line 3, you're trying to set char to player.Character, but player is set to game.Players. The following should work.

local player = game.Players
local players = player.LocalPlayer
local char = players.Character
humanoid = char:FindFirstChild("Humanoid")
function loadcharacter(respawn)
if humanoid.Health > 1 then
player:GetPlayerFromCharacter(respawn):LoadCharacter()
end
end

write this in a local script and place it into StarterGui

local player = game.Players.LocalPlayer
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
while wait() do
if humanoid.Health < 1 then
player:GetPlayerFromCharacter:LoadCharacter()
end

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