Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is It Possible to Click on a Part without ClickDetector?

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

1 comment

0

But you could use mouse.Target

3 answers

✓ Accepted answer

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

2 comments

0

Why would you even suggest SurfaceGuis first?

0

Cuz thats how we do it

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

2 comments

0

lmao hi great

0

wassup

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

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