Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do i detect clicking in a local part made by a local script with filtering enabled?

Asked by 5 years ago
Edited 5 years ago

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:

01local part = Instance.new("Part",game.Workspace)
02part.Size = Vector3.new(5, 75, 75)
03part.Position = Vector3.new(-107.425, 57.775, 250.71)
04part.Anchored = true
05 
06local function onTouch(hit)
07    print("test")
08end
09 
10part.Touched:connect(onTouch)

2 answers

Log in to vote
2
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago
Edited 5 years ago
01local part = Instance.new("Part")
02part.Size = Vector3.new(5, 75, 75)
03part.Position = Vector3.new(-107.425, 57.775, 250.71)
04part.Anchored = true
05part.Parent = workspace
06 
07local clickdetector = Instance.new("ClickDetector")
08clickdetector.MaxActivationDistance = 30
09clickdetector.Parent = part
10 
11 
12function onClicked()
13    --stuff here
14end
15 
16clickdetector.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!

0
This works. EnderCrayonBM 17 — 5y
0
waiting for this answer to be accepted Mr_Unlucky 1085 — 5y
0
Its been a day... Any second now Mr_Unlucky 1085 — 5y
0
Button is available now EnderCrayonBM 17 — 5y
0
mk Mr_Unlucky 1085 — 5y
Ad
Log in to vote
0
Answered by
karbis 50
5 years ago
Edited 5 years ago

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

1local char = -- put char here
2 
3char.bodypartname.Touched:Connect(function(hit)
4    if hit.Name == part name then
5        print("test")
6    end
7end)
0
That's the same thing? DeceptiveCaster 3761 — 5y
0
yea i did that already EnderCrayonBM 17 — 5y
0
Im pretty sure click detectors work on local scripts Fad99 286 — 5y
0
he did it in a part not a body part karbis 50 — 5y
0
its still the same thing, except less efficient bhqpping 80 — 5y

Answer this question