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 detect clicking in a local part made by a local script with filtering enabled?

I am trying to detect clicking a local part that is made by a local script that is in StarterGui with filtering enabled. This is my current script:

local part = Instance.new("Part",game.Workspace)
part.Size = Vector3.new(5, 75, 75)
part.Position = Vector3.new(-107.425, 57.775, 250.71)
part.Anchored = true

local function onTouch(hit)
	print("test") 
end

part.Touched:connect(onTouch)

2 answers

✓ Accepted answer
local part = Instance.new("Part")
part.Size = Vector3.new(5, 75, 75)
part.Position = Vector3.new(-107.425, 57.775, 250.71)
part.Anchored = true
part.Parent = workspace

local clickdetector = Instance.new("ClickDetector")
clickdetector.MaxActivationDistance = 30
clickdetector.Parent = part


function onClicked()
	--stuff here
end

clickdetector.MouseClick:Connect(onClicked)

All I did was remove the touch detection code and change it with ClickDetectors. These will allow you to detect if a part was clicked. We create it, set the maximum activation distance and parent it to the part. We make a function that connects to the MouseClick event. While we were talking you also spoke of using the click detector for viewing game pass products and what they do. For that you can insert the localscript into a ScreenGUI and change the visible property of a frame to true.

Hope this helps!

5 comments

0

This works.

0

waiting for this answer to be accepted

0

Its been a day... Any second now

0

Button is available now

0

mk

you simply cant, but you can try detecting when a body part touches the part like this

local char = -- put char here

char.bodypartname.Touched:Connect(function(hit)
	if hit.Name == part name then
		print("test")
	end
end)

5 comments

0

That's the same thing?

0

yea i did that already

0

Im pretty sure click detectors work on local scripts

0

he did it in a part not a body part

0

its still the same thing, except less efficient

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