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 make a part detect what parts it's touching after it's teleported?

I'm trying to make a drawing game. The basic structure is a tool that fires a ReplicatedEvent with mouse.Hit.p when activated, a script that makes a part at mouse.Hit.p when the ReplicatedEvent is fired, and then that part should change the color of touched parts. But it doesn't. Here's the script I'm trying to use:

while wait() do
	script.Parent.Touched:Connect(function(obj)
		print("Touched")
		if obj.Name == "Pixel" then
			obj.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
		end
	end)
end

I can't put a script into every single part that I want to change the color of, because there is 6000+ of them. I've been troubleshooting this for a while, and it does print Touched hundreds of times if you step on the part.

1 comment

0

You title is very confusing, and where did you put the script?

1 answer

✓ Accepted answer

You can try using hit in the touch function.

while wait() do
	script.Parent.Touched:Connect(function(hit)
		print("Touched")
		if hit.Parent.Name == "Pixel" then
			print("Found Pixel") --I put this here so if it does not work and it prints this then you know it is just the color that is not working.
			hit.Parent.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
		end
	end)
end

Hope this helps!

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