Is it possible to click a part and make it do something without Clickdetector?

I saw many games that a part was clickable without clickdetector and I don’t know why my script doesn’t work, I would like some help with this and I would really appreciate it. The script of mine is a Localscript inside the Part (Part52). The part’s name is “Part52” If you haven’t noticed.

And now I’m actually thinking that this isn’t possible

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

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

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst

3 Likes

It doesn’t work like that. The parts you clicked without a clickdetector were using SurfaceGuis and ImageButtons/TextButtons. Like UI elements

EDIT: Your code may work I don’t exactly know

It didn’t work sadly, but thank you

I am reffering to this article…

Localscripts dont run in the workspace, put it somewhere where it replicates to the Player.

1 Like

Like for example where? Startergui?

Yes, StarterGui, ReplicatedFirst, StarterPlayer (and Character), and in the Backpack would work.

1 Like

The thing is I’m trying to make it work with like TweenService so that the part will move from one position to another here is the code I’m trying:

local TargetPart = game.workspace.Part52
local Mouse = game.Players.LocalPlayer:GetMouse()

local twservice = game:GetService("TweenService")
local part = game.workspace.Part52

local Properties = {
	Position = Vector3.new(34.397, 11.052, 61.055)
}

local twinfo = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.In)
local tween = twservice:Create(script.Parent,twinfo,Properties)

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

And here is the error code:

TweenService:Create no property named ‘Position’ for object 'PlayerGui

local tween = twservice:Create(script.Parent,twinfo,Properties) here you are trying to tween the PlayerGui(script.Parent) do
local tween = twservice:Create(part ,twinfo,Properties)
Thats what you want I guess.

EDIT : I also suggest you to use UserInputService rather than Mouse events. reason : Reason

1 Like

Thank you man!! I have been trying to work this out for like 2 weeks, was trying to see If this was possible. Thanks

1 Like