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)
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!
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)