This is the error that comes up when I shoot the sky or above me. After it does not shoot anymore than bugs out.
[01:54:38.949 - Players.slinky22.Backpack.Gun.Guninfo:26: attempt to index field ‘Target’ (a nil value)]
script.Parent.Activated:Connect(function()
if Ammo>0 and not Reloading then
if debounce then
debounce = false
Ammo=Ammo-1
game.ReplicatedStorage.SoundEvent:FireServer()
game.ReplicatedStorage.RayCastEvent:FireServer(script.Parent.Hole.CFrame.Position, Mouse.Hit.Position)
if Mouse.Target.Parent:FindFirstChild("Zombie") then
script.Parent.Damage:FireServer(Mouse.Target.Parent, 30)
end
wait(0.5)
debounce = true
end
elseif Reloading == false then
Reload()
end
end)
I assume when you’re using Mouse you’re referring to the player mouse which you get from Player:GetMouse().
When your mouse isn’t over a part, Mouse.Target will be nil, so you should check if Mouse.Target is nil before indexing it.
Sidenote-
Do you have a remote which can be fired by the client to damage anyone? This seems very exploitable.
Target will set to nil when mouse is pointing on sky
script.Parent.Activated:Connect(function()
if Ammo>0 and not Reloading then
if debounce then
debounce = false
Ammo=Ammo-1
game.ReplicatedStorage.SoundEvent:FireServer()
game.ReplicatedStorage.RayCastEvent:FireServer(script.Parent.Hole.CFrame.Position, Mouse.Hit.Position)
if Mouse.Target and Mouse.Target.Parent
and Mouse.Target.Parent:FindFirstChild("Zombie") then
script.Parent.Damage:FireServer(Mouse.Target.Parent, 30)
end
wait(0.5)
debounce = true
end
elseif Reloading == false then
Reload()
end
end)