I am making damage dealt by guns rely on the position of the cursor on the screen, however when I shoot the npc or dummy bot I have put in to test, the console returns an error saying "attempt to index nil with 'Target' ". I'm slowly learning Lua but it can be challenging, any help would be highly appreciated!
There is more to the script but for simplicity I have included only the part with the issue. (Line 25 here)
-- global reload function --
local function Reload()
Reloading = true
wait(1)
Ammo = MaxAmmo
Reloading = false
end
-- holding item, connect --
script.Parent.Equipped:Connect(function()
print("Pistol equipped")
end)
-- click to attack --
script.Parent.Activated:Connect(function(Mouse)
print("fired "..Ammo)
if Ammo > 0 and not Reloading then
Ammo -= 1
print(Ammo)
script.Parent.GunShot:Play()
--recoils--
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 20)
end

6 comments
Just to clarify here, is the script a serverscript (not a localscript), or a localscript?
Alright, I've read your code further, and have concluded that this is a localscript.
Use player:GetMouse() instead of the first argument the activated function returns
How is it a localscript? You are gonna let yourself hear the gun sounds?? (not offending anyone here but pretty sure its a script (except the localscript is being weird lol))
it is a local script I never even thought of the rest of the server hearing the gun sound lol. I'll change some stuff up and probably be back tomorrow with more questions.
ooh ok that make sense