Hi, I want to use a gun, and click a part with the gun equipped, but it won’t let me, is there anyway around this?
Do you mind explaining more clearly?
You could get the Player’s mouse using Player:GetMouse()
inside a LocalScript, get the Mouse’s Target and check what it hit
I have a empty gun tool, and I want to click a button on a part, but the tool won’t let me click it.
https://gyazo.com/60e434df5f71b392736d16b7686e0130
as much as I know I don’t think there s a property of the tool to avoid this behavior but like many of the comments use mouse.target
Put this inside the Tool, it should be a LocalScript
:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
Tool.Activated:Connect(function()
local Target = Mouse.Target
print(Target)
if Target.Name == "TargetPart" then --It's either that or just "Target"
print("Found the target >:O")
--Do stuff here
end
end)
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
Tool.Activated:Connect(function()
print("Clicked!!!")
local Target = Mouse.Target
if Target:FindFirstChildWhichIsA("ClickDetector") then
print("Worked!!!")
--Do codehere
end
end)
I changed your code this way he doesn’t have to change every parts name to target part instead he can insert a click detector in the part he wants to click(which i am sure he already did)
Wait I’m just looking at this, you could just check the MouseHoverEnter/MouseHoverLeave
Events inside the ClickDetector’s Part if the player is holding a tool or not & if they are you could just change the Mouse’s Icon to the default click Icon maybe
This code will loop through the workspace to find any parts with a ClickDetector XP
local mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
for i, v in pairs(workspace:GetDescendants()) do
tool.Activated:Connect(function()
local target = mouse.Target
if v:FindFirstChildWhichIsA("ClickDetector") then
if target == v then
print("Click")
--do stuff
end
end
end)
end
why is the for loop necessary???
To find everything in the workspace with a ClickDetector
this should work
Under your click detector:
local function MouseClick()
-- do something
end
shared.ClickDetectors[script.Parent] = MouseClick
script.Parent.MouseClick:Connect(MouseClick)
in a server script:
game.ReplicatedStorage.FireClickDetector.OnServerEvent:Connect(function(player,cd)
if shared.ClickDetectors[cd] then
shared.ClickDetectors[cd](player)
end
end)
in a localscript:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
Tool.Activated:Connect(function()
local Target = Mouse.Target
if Target:FindFirstChildWhichIsA("ClickDetector") then
local cd = Target:FindFirstChildWhichIsA("ClickDetector")
cd.icon = "rbxassetid://2287179377"
game.ReplicatedStorage.FireClickDetector:FireServer(cd)
end
end)
but won’t we only need to check if the target has a ClickDetector
is the button a GUI???
I’m not entirely sure how they did it as I’ve never tried but I’ve seen games that to enable a tool they somehow have it set to left click. Probably isn’t much help but just thought I’d let you know.
I believe it is just a clickdetector
then my script will fix your problem
It didn’t find the click detector.
try putting a print()
in the if statement