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

How to detect a player's click without a tool? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

I'm trying to destroy a part when I click it. What I tried to do is below:

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
    mouse.Target:Destroy()
    warn("working")
end)

I'm using a local script but the warn doesn't work and neither does the destroying of the part. I also used a remote event to see if that would help, it accomplished nothing. I'd appreciate any help to this problem.

0
What do you need to work with a mouse click Pooglies 7 — 5y
0
if mouse.Target then mouse.Target:Destroy() end User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

using clickdetector. it works so well that it will work with a part, or a model. basically you do this, put a script file right under the object you want to destroy,

local part = script.Parent
local cd = Instance.new("ClickDetector", cd)
cd.MouseClick:Connect(function(player)
    -- do whatever you want to destroy the part.
end)
0
Thanks for the answer, but I was trying to do this with just the players mouse input. It turns out my problem was just a bug in that particular local script. cmgtotalyawesome 1418 — 5y
Ad

Answer this question