Hey, I’m trying to make a simple gun system with mouse.target, but whenever I clicked on any accessory it just doesn’t work. I it’s because I need to add another .Parent to it(bc mouse.target = the handle of the accessory), but even doing so it doesn’t work. Can someone help me with this?
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local Dmg = 1
tool.Activated:Connect(function()
if mouse.Target == nil then
return
else
if mouse.Target.Parent:IsA("Player") or mouse.Target.Parent:IsA("Model") then
local hum = mouse.Target.Parent:FindFirstChild("Humanoid")
if hum == nil then
return
else
if mouse.Target.Parent:IsA("Accessory") then
print("clicked on accessory")
local hum = mouse.Target.Parent.Parent:FindFirstChild("Humanoid")
hum.Health = hum.Health -Dmg
end
print(hum)
hum.Health = hum.Health -Dmg
end
end
end
end)
This is all in a local script
PS: I know I should make humanoids take damage in a local script, because it just doesn’t work, but for now I’m just testing. I will let a humanoid take damage with a bindable event later on.