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

How do I see what touched this part?

I have a script in a part that should change the color of the baseplate when it touched but i want to see if a player touched it but i dont know how can anybody please help?

script.Parent.Touched:Connect(function()
	print("something touched this")
	game.Workspace.Baseplate.BrickColor = BrickColor.Random()
end)

1 answer

✓ Accepted answer

You can pass a parameter through the function. Such as so:

script.Parent.Touched:Connect(function(PartThatTouched)
    print("something touched this, it's name is: "..PartThatTouched.Name)
    game.Workspace.Baseplate.BrickColor = BrickColor.Random()
end)

if you wanna make sure it is a player that touched this or anything that has a humanoid what you can do is:

script.Parent.Touched:Connect(function(PartThatTouched)
    print("something touched this, it's name is: "..PartThatTouched.Name)
	if PartThatTouched.Parent:FindFirstChild("Humanoid") then
   	 game.Workspace.Baseplate.BrickColor = BrickColor.Random()
	end
end)

1 comment

0

thx

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