I made a gun, and it shoots, but when i shoot someone dead, they are still alive on thier screen, but on my screen, they are dead, but dont respawn, please help me, ive been trying for hours to find a good way to script my gun without having any reloading or GUI stuff, so heres the script:
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
maxAmmo = 50
ammo = maxAmmo
rate = 0.1
firing = false
Canfire = true
reload = 5
damage = 20
script.Parent.Activated:Connect(function()
if ammo >= 1 and Canfire == true then
firing = true
repeat local bullet = Instance.new("Part", workspace)
bullet.CanCollide = true
bullet.Shape = "Ball"
bullet.Size = Vector3.new(0.4, 0.4, 0.4)
bullet.Material = "Neon"
bullet.BrickColor = BrickColor.new("Bright yellow")
bullet.CFrame = CFrame.new(script.Parent.Handle.Position, mouse.Hit.p)
local v = Instance.new("BodyVelocity", bullet)
v.Velocity = bullet.CFrame.LookVector*520
game.Debris:AddItem(bullet,5)
bullet.Touched:connect(function(hit)
if hit.Parent ~= Player.Character and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
bullet:Destroy()
end
end)
wait(rate)
until ammo < 1 or firing == false
end
end)
script.Parent.Deactivated:Connect(function()
if firing == true
then
firing = false
end
end)
mouse.KeyDown:connect(function(key)
if string.lower(key) == "r" and ammo < maxAmmo and firing == false then
Canfire = false
wait(reload)
ammo = maxAmmo
Canfire = true
end
end)

11 comments
This is due to Filtering Enabled. It prevents any action on the Client to make authoritative modifications to the Server—which is responsible for replicated the action to all other local machines. A ServerScript however, has this authority, therefore you’ll need to code the death-operation within said program, and call it to run through a RemoteEvent from the LocalScript.
umm, could you code that for me, im a really bad scripter, it would mean a TON to me, and im honest if you helped me!
See my previous answer on a similar question to get an understanding. If you cannot grasp it, I’ll reformat it to an answer here for you.
https://scriptinghelpers.org/questions/98366/why-does-my-timer-count-down-faster-when-more-clients-are-added#90880
so instead of when the bullets hitting the body and doing damage, it would connect to the event, but then would would i do? put another script?
You’re code, now that I read it is highly deprecated. I’d end up rewriting the entire program with the habit’s I have, and I am unavailable to do so at the time-being.
oh ok sad
You will have it call the opposite, :FireServer() then pick it up from a regular Script with .OnServerEvent
I will mostly start doing it anyway, since I am a coding fanatic. The only downside is I may take longer since I’m on mobile at the moment.
you could simplify the damaging by using Humanoid:TakeDamage(damage)
my notifications say that there is an answer to this, but i dont see one.