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?

Asked by 4 years ago

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)
1
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. Ziffixture 6913 — 4y
0
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! beargoespoopandpee 8 — 4y
0
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. Ziffixture 6913 — 4y
View all comments (7 more)
0
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? beargoespoopandpee 8 — 4y
0
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. Ziffixture 6913 — 4y
0
oh ok sad beargoespoopandpee 8 — 4y
0
You will have it call the opposite, :FireServer() then pick it up from a regular Script with .OnServerEvent Ziffixture 6913 — 4y
0
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. Ziffixture 6913 — 4y
0
you could simplify the damaging by using Humanoid:TakeDamage(damage) TheMaster9245 41 — 4y
0
my notifications say that there is an answer to this, but i dont see one. beargoespoopandpee 8 — 4y

Answer this question