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

My Touched event code isn't working, whats the problem?

here's my code:

script.Parent.Touched:connect(function()

script.parent.BrickColor = BrickColor.new("Bright red")

end)

it automatically becomes red without me touching the part please help me

2 answers

✓ Accepted answer

You need to check if a character stands on the part otherwise it would be red if anything touches it (such as an other part) so the updated code would be

script.Parent.Touched:Connect(function(part)
	
if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
script.parent.BrickColor = BrickColor.new("Bright red")
end
end)

please accept my answer if it works

As it is, your touched event is checking for everyone, you want to check if its a player touching. Theres a quick way to do that as seen here:

script.Parent.Touched:connect(function(Hit)
	local Plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
	if Plr then
		script.parent.BrickColor = BrickColor.new("Bright red")
	end
end)

This checks to see if the player is what touched it.

1 comment

0

connect is deprecated. Please use Connect instead.

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