Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my LocalScript believe I'm in a Team?

Okay so I've got a Folder in ServerStorage named Tags. Inside that Folder I've got two BillboardGuis, one named Blue Tag and the other named Red Tag. Then I've got a round-based-game so each time the player's Team change, I want to clone the Gui and place in their character's Head. So to do that I've got two scripts, one LocalScript and one Server Script. The LocalScript is placed in StarterPlayer -> StarterPlayerScripts. The Server Script is located in ServerScriptService. I've got a RemoteEvent in ReplicatedStorage called PlayerTeam. This is my code:

LocalScript

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local player = Players.LocalPlayer

local blueTeam = Teams:WaitForChild("Blue Team")
local redTeam = Teams:WaitForChild("Red Team")

local remEvent = game.ReplicatedStorage:WaitForChild("PlayerTeam")

player:GetPropertyChangedSignal("Team"):Connect(function()
	if player.Team then
		print("Team changed")
		if not player.Team == blueTeam and not player.Team == redTeam then
			return
		elseif player.Team == blueTeam then
			remEvent:FireServer("Blue Tag")
			print("Blue Tag")
		elseif player.Team == redTeam then
			remEvent:FireServer("Red Tag")
			print("Red Tag")
		end
	end
end)

Server Script

local remEvent = game.ReplicatedStorage:WaitForChild("PlayerTeam")

local ServerStorage = game.ServerStorage

remEvent.OnServerEvent:Connect(function(player, tag)
	if player and player.Character and ServerStorage.Tags:FindFirstChild(tag) then
		local redTag = player.Character:FindFirstChild("Red Tag")
		local blueTag = player.Character:FindFirstChild("Blue Tag")
		
		if redTag then
			redTag:Destroy()
		elseif blueTag then
			blueTag:Destroy()
		end
		
		local clonedTag = ServerStorage.Tags:FindFirstChild(tag):Clone()
		clonedTag.Parent = player.Character.Head
	end
end)

Now the problem is that when a new player joins, they aren't in any Team, they are located in the Lobby. But my LocalScript believe they are so it Fires the RemoteEvent and prints Red Tag. Every time, it's Red Tag. And I just can't figure why. I've checked the Player Instance in the Explorer and the player isn't in any Team. I even typed in the command box print(player.Team) and it prints nil. On line 12 in the LocalScript I used to have this;

if player.Team and player.Team ~= nil then

or

if player.Team and not player.Team == nil then

but then it didn't work at all.

Any help would be appreciated! Thank you!

1 answer

✓ Accepted answer

From what I remember, I remember the player is assigned a team, just not viewable. I think it was the "default team" or something, and that would show up if the player was not assigned a team even though it was created. Idk man, don't quote me on this.

3 comments

0

Okay that makes no sense.. but it gave me an idea so I'll just try something real quick

0

Okay thank you. Sorry but your answer didn't really help. You just gave me an idea so I solved it myself. I'll accept this anyway

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.