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

How do I respawn a player via a LocalScript?

Asked by
Melthor 10
9 years ago

I need help re-spawning a player via a LocalScript. Is there a certain command to do it?

Player = game.Players.LocalPlayer;
Character = Player.Character;

How do I re-spawn [[Player]]?

1
LoadCharacter is the function you would want to use, however that is recommended for use in Server Sided script. M39a9am3R 3210 — 9y
0
WHat is the recommended function/event for LocalScripts? LoadCharacter works perfectly with my current local script. Melthor 10 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

You could kill the player;

Character:BreakJoints()

-- or

Character.Humanoid.Health = 0

Or, you could set up a RemoteEvent, which is linked to a Server Script.

LocalScript:

local ra = game.Workspace.RespawnPlayer

ra:FireServer(game.Players.LocalPlayer) -- fires the event

Script:

local ra = game.Workspace.RespawnPlayer

ra.OnServerEvent:connect(function(player) -- listens for the event
    player:LoadCharacter() -- resets the player
end)
0
This is even more advanced. I don't know if it works, but if it does, I shall use this, since it saves me time. Melthor 10 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

there is an exemple of what you can do for respawning the local players :

local player = game.Players.LocalPlayer -- here i defined the variable "player"
local character = player.CharacterAdded:wait() -- here i defined the variable "character"

 wait(1) -- i put a wait here because because if i don't, it will crash.. (You don't need to put the wait if you have a condition in your if because he i did like if the character is not nil then it will load the character.)

 if character then  -- here i did "if" the character ~= nil then
    player:LoadCharacter() -- its will load the character (respawn)
 end -- here i closed the if. 

I put this localscript in the backpack.

sorry for my bad english o-o.

0
Your wait(1) is not required. RepeatLua 90 — 9y
0
Yep. The script I defined at the start also works with Player:LoadCharacter();. Thank you for showing me. Melthor 10 — 9y

Answer this question