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

How can I make the player respawn at the Team Spawn after clicking a Gui Button?

local startergui = game.StarterGui

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent:Destroy()
	game.StarterGui:WaitForChild("MotherViewPrison",1):Destroy()
	game.StarterGui:WaitForChild("Prisoners", 1):Destroy()
	game.Players.LocalPlayer.Team = game.Teams.Police
	game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	game.Workspace.CurrentCamera.CameraType = "Custom"
end)

Even when the player dies, it doesn't load at the Team Spawn

1 comment

0

Make sure to turn off CharacterAutoLoading in a server script which can be done by doing game.Players.CharacterAutoLoads = false and to make sure you use Player:LoadCharacter() which can be done through server as well as client.

2 answers

Maybe try:

local plr = sceipt.Parent.Parent.Parent.Parent.Parent.Name

script.Parent.MouseButton1Click:connect(function()
game.Players[plr].BrickColor = BrickColor.new("Color") -- Put the color of your team in there

game.Players.LocalPlayer.Character.Humanoid.Health = 0

One thing that might not work in the script is from lines 5 and 6 I know this isn’t really the answer to your question but it’s one of the answers to fixing your script. If the script is locally I’d suggest you not use StarterGui as that won’t do anything you would rather do.

game.Players.LocalPlayer.PlayerGui 

-- Instead of game.StarterGui

So switch out lines 5 and 6 for

-- Line 5 
game.Players.LocalPlayer.PlayerGui:WaitForChild("MotherViewPrison",1):Destroy()
-- Line 6
game.Players.LocalPlayer.PlayerGui:WaitForChild("Prisoners", 1):Destroy()
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent:Destroy()
    player.PlayerGui:WaitForChild("MotherViewPrison",1):Destroy()
    player.PlayerGui:WaitForChild("Prisoners", 1):Destroy()
   
 -- The team changing line I removed it because you would need RemoteEvents to change the player’s team or else nobody will see the player being on the police team and the script won’t work so consider learning RemoteEvents/RemoteFunctions
  
  -- Link To RemoteEvent And FE Stuff: 
https://developer.roblox.com/api-reference/class/RemoteEvent
    
    player:LoadCharacter()  -- Insta Respawns The Player
end)

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