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

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

Asked by 5 years ago
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

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. AnnaVonWachstein 7 — 5y

2 answers

Log in to vote
0
Answered by
Rynappel 212 Moderation Voter
5 years ago

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
Ad
Log in to vote
0
Answered by
FPSVision -14
5 years ago
Edited 5 years ago

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)

Answer this question