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

How do you find a players teamcolor in a normal script via the hit function?

I've been trying to make this "capture the flag" game, and when I was testing it I realised that everything was client based, so if the red team captured the flag, then blue came and captured it, it would still appear red to the red team players. Here is my script:

local flag = workspace.Flag
local flagchanger = workspace.CaptureFlag
local player = game.Players.LocalPlayer
local status = game.StarterGui.FlagStatus.Frame.Owner

flagchanger.Touched:Connect(function()
	if player.TeamColor == BrickColor.new("Maroon") then
		flag.Flag.BrickColor = BrickColor.new("Maroon")
		-- other stuff here
		print("done")
	else
		flag.Flag.BrickColor = BrickColor.new("Electric blue")
		 -- other stuff here
		print("done")
	end
end)

This script works in a localscript but not in a normal script. What do I need to change to fix this?

2 comments

0

Don’t use a local script, don’t use local player.

0

I know but how would I make it so the normal script could find the players TeamColor via the hit function?

1 answer

✓ Accepted answer

Put this in a server script:

local flag = workspace.Flag
local flagchanger = workspace.CaptureFlag

flagchanger.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		if player.TeamColor == BrickColor.new("Maroon") then
			
			flag.Flag.BrickColor = BrickColor.new("Maroon")
			-- other stuff here
			print("done")
			
		else
			
			flag.Flag.BrickColor = BrickColor.new("Electric blue")
			-- other stuff here
			print("done")
			
		end
		
	end
	
end)

Also for "status", when the game initializes, the contents from StarterGui go under game.Players.playerName.PlayerGui, so it needs to be referenced there. Hovewer, this is a server script, so if you are actually using that you should use a remote event to fire to the client, and you can do game.Players.LocalPlayer.PlayerGui.FlagStatus.Frame.Owner. Hope this helped!

1 comment

0

Thank you very much! :))

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