Team Changer not spawning in the correct location

I’ve been making a Team Changer for my United States Coast Guard and I want it to spawn in the correct location when changing teams.

It spawns me at my original team’s spawn and not the one that I’ve selected.

Screenshot:


(GUI IN THE WAY BUT IT SPAWNED ME AT MY ORIGINAL TEAM LOCATION)

I’ve tried searching up on Youtube and cannot find answers, I’ve had multiple of my other friends have this problem and even commissions I’ve been doing trying to solve this solution.

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
	if plr:GetRankInGroup(14761109) >= 225 then
		plr.TeamColor = BrickColor.new("Gold") -- (BY THE WAY, I RESPAWN)
	end
end)
1 Like

change the team, not the color.

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
	if plr:GetRankInGroup(14761109) >= 225 then
		plr.Team =  game:GetService("Teams")["Coast Guard Personnel"]
	end
end)
1 Like

I’ve tried that before and it does the same thing.

1 Like

Yeah, it’s doing the same thing and spawning in the original team’s location still.

1 Like

This is because of replication boundaries. The server does not recognize that you have set your team color because if it is changed on the client, only that client can see it, but if it’s changed on the server, everyone can see it.

Let’s say you have a RemoteEvent in ReplicatedStorage named “ChangeTeam”.

Server Script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("ChangeTeam")

event.OnServerEvent:Connect(function(plr:Player,team:Team)
     if team and team:IsA("Team") then-- basically checking if the team argument is valid
        if plr:GetRankInGroup(14761109) >= 225 then
            plr.Team = team 
        end
     end
end)

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("ChangeTeam")

script.Parent.MouseButton1Click:Connect(function(click)
    if plr:GetRankInGroup(14761109) >= 225 then
		event:FireServer(path to team object goes here)
	end
end)

Sorry if it doesn’t work, as I made this in the DevForum and not Studio.

4 Likes

Hey, can you explain path to team object?

1 Like

Basically, the full name of the object
Something like this:


local Teams = game:GetService("Teams")

local path = Teams.MyTeam1

or this, but GetService is recommended


local path = game.Teams.MyTeam1

You can get an Team’s (any instance actually) FullName by calling its :GetFullName() method.

print(path:GetFullName()) -- should return Teams.MyTeam1

It does not include the game. part, however.

1 Like
local plr = game.Players.LocalPlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("TeamChange")
local Teams = game:GetService("Teams")

local path = Teams.Headquarters

script.Parent.MouseButton1Click:Connect(function()
	if plr:GetRankInGroup(14761109) >= 225 then
		Event:FireServer(path)
	end
end)

print(path:GetFullName())
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("ChangeTeam")

event.OnServerEvent:Connect(function(plr:Player, team:Team)
	if team and team:IsA("Team") then-- basically checking if the team argument is valid
		if plr:GetRankInGroup(14761109) >= 225 then
			plr.Team = team 
		end
	end
end)

Is there anything I need to change to make it work? @Trafficboy05

1 Like

You should be good to go, although you can remove the print statement, and probably use :WaitForChild() when getting the team, like this: local path = Teams:WaitForChild("Headquarters")

1 Like

that’s great dude! hope you figure it out! :smile:

1 Like

Doesn’t work, late reply

##############

1 Like

Are there any errors in the console?

1 Like

Sorry another LATE reply, I’ll check.

All I got was this:

No other errors about teams except this.

You have to make a RemoteEvent in ReplicatedStorage named “ChangeTeam”

I have added that already

#R$#553sdrfdwdedd

Never mind it worked, thanks!

434rrwewsw

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.