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

Help with respawning? [closed]

Asked by 10 years ago

How would I make this script below to respawn a character, but not set their health to 0?

script.Parent.MouseButton1Click:connect(function()
    local p = game.Players.LocalPlayer
    p.TeamColor = BrickColor.new("Medium stone grey")
end)

Locked by adark and TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

Use the LoadCharacter method of their Player.

However, since this is a LocalScript, you're going to have to use something (preferably a Remote* object) to tell the Server to do this, as LoadCharacter should only be used from a Script:

--Server Script
local rs = Instance.new("RemoteEvent", Game:GetService("ReplicatedStorage"))
rs.Name = "Respawn"
rs.OnServerEvent:connect(function(player)
    player:LoadCharacter()
end)
--Local Script (added a debounce)
local rs = Game:GetService("ReplicatedStorage"):WaitForChild("Respawn")

local deb = false
script.Parent.MouseButton1Click:connect(function()
    if deb then return end
    deb = true --It doesn't close because I assume the PlayerGui gets reset.
    local p = game.Players.LocalPlayer
    p.TeamColor = BrickColor.new("Medium stone grey")
    rs:FireServer()
end)
Ad