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

I made a GUI for team selection but I have no idea how to teleport the players to their team spawns?

Asked by 7 years ago
Edited 7 years ago

I tried something like this

local player = game.Players.LocalPlayer
local Blue_Team = game.Teams.Blue_Team
local Button = game.StarterGui.Team_GUI.Frame.Blue_Team
local gui = script.Parent.Parent
local Blue_Spawn = game.Workspace.Blue_Base.Blue_Spawn



local function teleport()

end
local function onClicked(mouse)
    player.TeamColor = BrickColor.new("1010")
    player.Position = Vector3.new(115, 1.5, 138)
    gui:Remove()
end
script.Parent.MouseButton1Down:connect(onClicked)

2 answers

Log in to vote
0
Answered by 7 years ago

Can't you make it so that once clicked the player will reset and just spawn to it's spawn location?

local player = game.Players.LocalPlayer

MouseButton1Down:connect(function()
    player:WaitForChild("Character"):WaitForChild("Humanoid").Health = 0
end)

then it will auto-spawn in the spawn position. Accept answer and upvote if helped.

Ad
Log in to vote
0
Answered by 7 years ago

Hello,

I'm assuming you already have a SpawnLocation for the team you are trying to set in this script. You can do this in a simpler way, after you set the player's TeamColor, you can just use :LoadCharacter(). LoadCharacter is different than setting a player's health to 0 because LoadCharacter immediately respawns the player and doesn't make them wait for the 5 second delay. PS: You can also set a player's TeamColor by using, player.TeamColor = game.Teams["Team Name"].TeamColor.

Example of new code:

local player = game.Players.LocalPlayer
local Blue_Team = game.Teams.Blue_Team
local Button = game.StarterGui.Team_GUI.Frame.Blue_Team
local gui = script.Parent.Parent
local Blue_Spawn = game.Workspace.Blue_Base.Blue_Spawn



local function teleport()

end
local function onClicked(mouse)
    player.TeamColor = BrickColor.new("1010")
    player:LoadCharacter()
    gui:Remove()
end
script.Parent.MouseButton1Down:connect(onClicked)

**If this worked for you please accept my answer. If you have any further questions, don't hesitate to ask. **

Answer this question