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

How do I make a player go to a particular spawn location when they chose a particular team?

Asked by 4 years ago

For example, when the player chooses team "prisoner" then they spawn in the jail, whereas if the player choose team "police" they spawn in a police station.

I have this code here trying to do what I mentioned up:

localscript:

local RemoteEvent = game.ReplicatedStorage.ChangeTeam
local player = game.Players.LocalPlayer

frame.prisoner.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer(BrickColor.new(CitizenColor))
    frame.Visible = not frame.Visible
player.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.citizen.Position + Vector3.new(0, 10, 0))

Remote Event: "ChangeTeam"

SeverScriptService:

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player,teamColor)
    player.TeamColor = teamColor
    player:LoadCharacter()

end)

But the problem is that the player spawns on where I want it to spawn, then it immediately spawns on another spawn location. The Humanoid won't stay in the place where I want it to spawn :/

How do I fix this problem so that when a player chooses "prisoner" or any other team and spawns at a particular place set for that team.

1 answer

Log in to vote
0
Answered by 4 years ago

Local script:

local RemoteEvent = game.ReplicatedStorage.ChangeTeam
local player = game.Players.LocalPlayer

frame.prisoner.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer(player,CitizenColor)
    frame.Visible = not frame.Visible
player.Character.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.citizen.Position + Vector3.new(0, 10, 0))
end)

Global script in ServerScriptService:

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player,CitizenColor)
    player.TeamColor = game.Teams.CitizenColor.TeamColor
    player:LoadCharacter()
end)

So that should work. Just change CitizenColor to whatever your prisoner's team is called.

If that helped please up vote and accept this answer.

All the best,

PrismaticFruits

0
Won't there be issues with asynchronously calling LoadCharacter from the server and setting the CFrame of the client at the same time? f59ph_iv 0 — 4y
0
I guess not? PrismaticFruits 842 — 4y
Ad

Answer this question