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 4 years ago
Edited 4 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:

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

Log in to vote
2
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago
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!

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

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)
0
That's the same thing? DeceptiveCaster 3761 — 4y
0
yea i did that already EnderCrayonBM 17 — 4y
0
Im pretty sure click detectors work on local scripts Fad99 286 — 4y
0
he did it in a part not a body part karbis 50 — 4y
0
its still the same thing, except less efficient bhqpping 80 — 4y

Answer this question