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

How can I make a block to a color when a player steps on it?

How can I make it so when a player that is on a team steps on a block and then it changes color? Ex: Player on red team steps on a block, it turns red. Here is what I have right now:

function Change(hit)
	local h=hit.Parent:FindFirstChild("Humanoid")
	if h~=nil then
		script.Parent.BrickColor = BrickColor.new("Team color")
	end
end

script.Parent.Touched:connect(Change)

1 answer

✓ Accepted answer

Here is my script that works:

local part = script.Parent --defines the variable "part"
part.Touched:connect(function(hit) -- do stuff when "part" is touched
	if hit.Parent:FindFirstChild("Humanoid") then -- if the thing that part is touching has a humanoid then (pretty much detects if it's a player)
		local player = game.Players:FindFirstChild(hit.Parent.Name) -- defines the variable, "player" as the player that touched the part
		part.BrickColor = player.TeamColor -- changes brickcolor to the player's teamcolor
	end
end)

1 comment

0

Thanks!

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