Hello, I have made this code where when a prisoner or citizen hits a part they change to crims. It succefully worked. I wanted it so if a police toches the part it will stay the same team but it did not work. Please have a look at my code and see if you can help me fix it. The main code needing to be fixed is at the very bottom.

The main code is at the bottom.

local RemoteEvent = game.ReplicatedStorage.ChangeTeam
local CriminalEvent = game.ReplicatedStorage.Criminals  -- variables
local PoliceEvent = game.ReplicatedStorage.Police

local CrimFrame = game.StarterGui.ScreenGui.CrimsTeam -- ignore this and go to bottom

local PoliceDevice = game.Teams

local PoliceTeamTest = game.Teams.Police

local player = game.Players.LocalPlayer

local frame = script.Parent:WaitForChild("Frame")

local player = game.Players.LocalPlayer

local red = game.Workspace.Parts.RedBrick

local CitizensColor = "Lime green" 
local PoliceColor = "Cyan"
local PrisonersColor = "Bright orange"
local CriminalsColor = "Crimson"

frame.Prisoners.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(BrickColor.new(PrisonersColor))
end)


frame.Police.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(BrickColor.new(PoliceColor)) 
end)



frame.Citizens.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(BrickColor.new(CitizensColor))
end)


 -- THE CODE IS BELOW!

red.Touched:Connect(function()
	CriminalEvent:FireServer(BrickColor.new(CriminalsColor))
	local PoliceTestRun = 100
	if player.TeamColor == PoliceColor and PoliceTestRun == 100 then 
		player.TeamColor = PoliceColor -- not keeping the police the same team code
	end
end)

4 comments

0

Can you show us the remote events's code?

0

A. Why are you doing Touched on the client B. Why are you attempting to change the TeamColor locally

0

Hey jack! Sure I will do that later

0

Why are you using team colour as a comparison, why not just check the player team itself. Maybe you should, in the remote event stuff, check if the player is not a police, then change it, instead of changing it back.