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

How would I fix this script to make a player switch teams when they hit a block?

local part = script.Parent
part.Touched:connect(function(hit)
	if hit.Parent then
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if hum then
			local player = game.Players:GetPlayerFromCharacter(hum)
				player.Parent.TeamColor = BrickColor.palette("Fossil")
		end
	end
end)

Title is self-explanatory.

1 answer

✓ Accepted answer

Here you go

local part = script.Parent

part.Touched:connect(function(hit)
	local parent = hit.Parent --the part that touched parent
	if game.Players:GetPlayerFromCharacter(parent) then --If player
		local player = game.Players:FindFirstChild(parent.Name)--Finds player
    	player.TeamColor = BrickColor.new("Fossil")--Team color
	end
end)

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