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

Is It Possible to Click on a Part without ClickDetector?

Asked by
KenUSM 53
7 years ago

Is it possible to click on a part without having to spam All the Parts with Click Detectors for my game?

0
But you could use mouse.Target thesit123 509 — 7y

3 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

There are various ways you could do this - here are two of them:


The first way is to make a SurfaceGui. Put it in StarterGui or someplace else where it can get to PlayerGui [1]. If it is in PlayerGui, objects in the SurfaceGui can be interacted with, otherwise it won't work.

Make sure to set the Adornee property of the SurfaceGui to the part you want it to be on.

Then, you simply detect the button in the SurfaceGui being pressed:

-->> LocalScript inside the SurfaceGui

local Button = script.Parent:WaitForChild("TextButton")
Button.MouseButton1Click:Connect(function()
    print("Clicked!")
end)

The second way is to detect the mouse being clicked with the player's Mouse object, then detect what it was clicked on using the Target property.

-->> LocalScript inside PlayerScripts [1]

local TargetPart = game.Workspace:WaitForChild("Part")
local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.Button1Down:Connect(function()
    local Target = Mouse.Target
    if Target == TargetPart then
        print("Clicked!")
    end
end)

[1] These places are located in the Player object. You can only see them in the Explorer when testing.

Hope I helped!

~TDP

0
Why would you even suggest SurfaceGuis first? Link150 1355 — 6y
0
Cuz thats how we do it kidsteve923 139 — 3y
Ad
Log in to vote
1
Answered by 7 years ago

Sure their is... just script the variable called "PartToGetTouched" as your part

--localscript
local PartToGetTouched -- change to your part
wait(1)
local player = game.Players.LocalPlayer
local mouse = player.Mouse
local target = mouse.Target

if mouse.Target.Name == PartToGetTouched then
    mouse.Button1Down:connect(function()
        -- the code you want can go in here....
    end)
end

Feel free to accept this answer if it works, you can also use a billboard gui on all sides of the part and paste a textbutton into them

WARNING.. THE PART TO GET TOUCHED MUST HAVE A SPECIFIC NAME IF YOU RENAME IT TO GAME.WORKSPACE.PART or their will be so many parts that this script may not work...

anyways thx for using

0
lmao hi great raid6n 2196 — 4y
0
wassup greatneil80 2647 — 4y
Log in to vote
-1
Answered by 7 years ago

Use a local script that fires when the player clicked. Then check if miuse.target = your part, then fire a remote function.

Answer this question