I have a script where when a player presses a button, they get teleported to their spawn:
local Plr = game.Players.LocalPlayer script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Visible = false Plr.Team = game.Teams.Prisoner Plr.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Prisoner.Position + Vector3.new(0, 10, 0)) workspace.CurrentCamera.CameraType = Enum.CameraType.Custom end)
I have a spawn location called 'Prisoner' and the team colour is set exactly to the prisoner team colour, with both 'Neutra'l and 'AllowTeamChangeOnTouch' set to false.
However, whenever a player dies, it doesn't respawn it back to their team's spawnlocation, but spawns them in the middle of the map.
How do I fix this problem?
Any help is appreciated.
You can use the RespawnLocation
property of Player
to assign a designated spawn-location of the respective Team.
local Player = game:GetService("Players").LocalPlayer Player.RespawnLocation = workspace[Player.Team.Name]
Ensure the Instance is a SpawnLocation
and is a child of workspace
If you wish to have them respawn at an Instance that is not a SpawnLocation
, you can adjust their position manually as in your original Script. To do so when they reload, use the CharacterAdded
signal to run the code when their avatar is rebuilt.
You can use a CharacterAdded
event to set their position based on the assigned team.
local Player = game:GetService("Players").LocalPlayer local function PlaceCharacterAtTeam(Character) if not (Character) return end local TeamSpawn = workspace[Player.Team.Name] if (TeamSpawn) then Character:MoveTo(TeamSpawn.CFrame.p + Vector3.new(0,3,0)) end end Player.CharacterAdded:Connect(PlaceCharacterAtTeam)