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

How do I make a Player spawn in a certain team spawn when they die?

Asked by 4 years ago

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.

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
0
I typed in this code: Player.Prisoner = workspace[Player.Team.Name] (where Prisoner is the name of the SpawnLocation under workspace. Then Roblox outputs with this message: Unselected is not a valid member of Workspace. How do I fix this problem? JealousRegretHate 34 — 4y
0
When I type in the CharacterAdded event, this message occurs: Model:SetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this. How do I fix this problem? Thank you JealousRegretHate 34 — 4y
0
I find that odd, Player.Prisoner will fail, leave it as Player.RespawnLocation = workspace[Player.Team.Name] Ziffixture 6913 — 4y
0
It is trying to find a Part in workspace that matches the name of their Team, ensure the SpawnLocation is called Prisoner, as well as team Ziffixture 6913 — 4y
View all comments (3 more)
0
The reason why I couldn’t is because they had no team, make sure the player is a Prisoner before running that line Ziffixture 6913 — 4y
0
With the modified CharacterAdded code, try it with MoveTo Ziffixture 6913 — 4y
0
Both codes shows no errors in the Roblox output, but it still spawns my player in the middle of the map. JealousRegretHate 34 — 4y
Ad

Answer this question