Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this gun kill people entirely?(Unanswered)

Asked by 4 years ago

I made a gun, and it shoots, but when I shoot someone dead, they are still alive on their screen, but on my screen, they are dead but don't respawn, please help me, I've been trying for hours to find a good way to script my gun without having any reloading or GUI stuff, so here's 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)
0
im sorry i brought this back, but my notifications said that my older post about this was answered, but there was no answer when i checked it. beargoespoopandpee 8 — 4y

1 answer

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
4 years ago

they are still alive on their screen, but on my screen, they are dead but don't respawn

This means you are using a localscript, you will need to use remotefunctions/events and a script to make the damage work, also remember to protect your remotefunction/events!

0
i know, but i really dont know how to do that, because i am mega nooby at scripting, so maybe a little bit of instruction to help me? beargoespoopandpee 8 — 4y
Ad

Answer this question