Help with Gun Damage


I’ve made a gun without Raycasting, but it doesn’t deal damage using Mouse.Target. Everything else works, but the Damage doesn’t. There are no errors in the output. Please advise!

Mouse.Target will automatically filter out the local players’ character, are you attempting to err… test the weapon on your own character?
Aside from that I would try adding debug statements within your conditional statements to see where the code gets to and where it isn’t. Try printing on the server event the player, the target and the damage… as well as within the localscript for whether it’s firing or reloading.
I also see a potential issue in your code hanging up when it reaches while wait() do… would this not be an infinite loop?

It’s supposed to be an infinite loop, to show the ammo on GUI.

Would you not be able to just set the text once every time the ammo counter is decremented?

If you’re raycasting use the raycast results instead.

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/Raycast

im not using raycasting for this weapon

Is the gun script a LocalScript? it has to be a LocalScript if it wants to fire the remote. If it is just a Script, then just deal the damage right at that line.

If it’s a LocalScript, I can see just a tiny problem Player.leaderstats.Kills.Value += 1 is updated client sidedly. Nobody else can see it.

Also 1 tini tiny problem with the Script is that exploiters can do:

local remote = game:GetService("ReplicatedStorage").DealDamage
game:GetService("RunService").Renderstepped:Connect(function()
    for i,v in pairs(game:GetService("Players"):GetPlayers()) do
        remote:FireServer(v.Character, math.huge())
    end
end)

An additional problem that the script have is:

while wait() do
    TextLabel.Text = Ammo.."/"..MaxAmmo
end

Remove the while loop and put TextLabel.Text = Ammo.."/"..MaxAmmo after the ammo decrement (Ammo -= 1 line). The way you do it will probably crash the game after 100 shots as the while loop is never broken yet you keep making another one.

1 Like