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

Why won't this respawn script work?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
1
Answered by 8 years ago

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

Ad
Log in to vote
1
Answered by 8 years ago

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

Answer this question