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

My gun hurts the shooter?

Asked by
Mr1Vgy 30
9 years ago

Ok so I have this gun and I'm trying to make it so that it only kills zombies and not players, but right now when you shoot it, it hurts the shooter. Can anyone help?

local tool = script.Parent
local user

tool.Equipped:connect(function(mouse)
    user = tool.Parent
    mouse.Button1Down:connect(function()
        if script.Parent.Ammo.Value > 0 and script.Parent.shoot.Value == true then
            local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
            local hit, position = game.Workspace:FindPartOnRay(ray, user)

            local humanoid = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
            if humanoid and hit.Parent:FindFirstChild("Follow")then
                humanoid:TakeDamage(30)
            end 
            local distance = (position - tool.Handle.CFrame.p).magnitude
            local rayPart = Instance.new("Part", user)
            rayPart.Name = "RayPart"
            rayPart.BrickColor = BrickColor.new("Dark stone grey")
            rayPart.Transparency = .5
            rayPart.Anchored = true
            rayPart.CanCollide = false
            rayPart.TopSurface = Enum.SurfaceType.Smooth
            rayPart.BottomSurface = Enum.SurfaceType.Smooth
            rayPart.FormFactor = Enum.FormFactor.Custom
            rayPart.Size = Vector3.new(.2, .2, distance)
            rayPart.CFrame = CFrame.new(position, tool.Handle.CFrame.p)*CFrame.new(0, 0, -distance/2)
            game.Debris:AddItem(rayPart, .1)
            script.Parent.Handle.FireSound:Play()
            script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
            --game.Players.LocalPlayer.PlayerGui.Main.inGame.AmmoGui.ammo.Text = script.Parent.Ammo.Value--]]
        elseif script.Parent.Ammo.Value == 0 then
            for i = 1, script.Parent.ReloadAmmo.Value do
                wait(.1)
                script.Parent.Ammo.Value = script.Parent.Ammo.Value + 1
                script.Parent.shoot.Value = false
                --game.Players.LocalPlayer.PlayerGui.Main.inGame.AmmoGui.ammo.Text = script.Parent.Ammo.Value
            end
            script.Parent.shoot.Value = true
        end
    end)

    --[[local on = false
    mouse.KeyDown:connect(function(key)
        if string.lower(key)== "e" then
            if on then
            on = false
            for i = 1, 9 do
                wait(0.01)
                game.Workspace.CurrentCamera.FieldOfView = game.Workspace.CurrentCamera.FieldOfView + 5
            end
            game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
            elseif not on then
            on = true
            for i = 1, 9 do
                wait(0.01)
                game.Workspace.CurrentCamera.FieldOfView = game.Workspace.CurrentCamera.FieldOfView - 5
            end
            game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
        end
        end
    end)--]]
end)

0
That is a loooooonnngggg code. EzraNehemiah_TF2 3552 — 9y
0
There is nothing wrong with it. I executed the same code (removing some lines not needed for the firing), and it worked just fine. It didn't damage my character at all. Tkdriverx 514 — 9y
0
LordDragonZord. It's not that long. I've written a script that's over 2000 lines SchonATL 15 — 9y

Answer this question