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

Team Change but executes for a certain team?

trying to make a border-like game, and i am trying to create a certain point of the map where immigrants turn to citizens, but i cant do it without changing the Patrol team to citizens here is my code so far

tm = script.Parent

function onTouched(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h ~= nil then
		local n = hit.Parent
		local p = game.Players:FindFirstChild(""..n.Name.."")
		if p ~= nil and p.TeamColor == "Bright red" then
			p.TeamColor = tm.BrickColor
		end
	end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

Your problem is on line 08. You're asking the script if p's TeamColor is equal to the string "Bright red", when you should actually be comparing color to color.

I never understood why people access the TeamColor property when it can be done way simpler:

if p~= nil and p.Team == game.Teams.Immigrants then
	p.Team = game.Teams.Citizens
end

Some other changes I suggest:

  • Put 'local' infront of your variables and functions, it's a good practice (line 01 and 03)

  • On line 04, it's also a good practice to use FindFirstChildOfClass("Humanoid") instead, just to protect against the unlikely event there's another item there named Humanoid.

  • As an easier alternative to what you did on line 07, you can use local p = Players:GetPlayerFromCharacter(hit.Parent), if there's a humanoid.

1 comment

0

Thanks

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