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

How do I add damage to other players and not damage myself?

Asked by 4 years ago
Player = game.Players.LocalPlayer
local Mouse = game.Players.LocalPlayer:GetMouse()
Ammo = 1
AmmoE = 1
AmmoD = 1
game:GetService("UserInputService").InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.F and Ammo>0 then
        local x = Instance.new("Part", workspace)
        x.Shape = "Ball"
        x.BrickColor = BrickColor.new("Deep orange")
        x.Transparency = 0.3
        x.TopSurface = "Smooth"
        x.BottomSurface = "Smooth"
        x.CanCollide = false
        x.Parent = workspace
        x.CFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-6)
        local v = Instance.new("BodyVelocity")
        v.Parent = x
        v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        v.Velocity = (x.Position - Mouse.hit.p).unit*-100

        Ammo = Ammo - 1

        if x.Touched:Connect(function()
            if AmmoE == 1 then
                x.Transparency = 1
                local Explosion = Instance.new("Part", workspace)
                Explosion.Shape = "Ball"
                Explosion.BrickColor = BrickColor.new("Deep orange")
                Explosion.TopSurface = "Smooth"
                Explosion.BottomSurface = "Smooth"
                Explosion.CanCollide = false
                Explosion.Parent = x
                Explosion.Transparency = 0.7
                Explosion.Size = Vector3.new(20,20,20)
                Explosion.Position = x.Position
                Explosion.Anchored = true
                AmmoE = AmmoE - 1
                local StartNumber = 24
    if Explosion.Touched:Connect(function()
        if AmmoD == 1 then
            game.Players.LocalPlayer.Character.Humanoid:TakeDamage(3)
            AmmoD = AmmoD - 1
        end
    end)

    then end
                for i = 1,4,1 do
                Explosion.Size = Vector3.new(StartNumber, StartNumber, StartNumber)
                StartNumber = StartNumber + 4
                wait(.05)
            end

            wait(0.1)
                Explosion:Destroy()
            AmmoE = 1
    end
end)
            then wait(2)
                Ammo = 1
                AmmoD = 1
        end
    end
end)

Full Code

1 answer

Log in to vote
0
Answered by 4 years ago
Edited by DeceptiveCaster 4 years ago

Very vague question. However, I think you should change this part of the code to this:

if Explosion.Touched:Connect(function(plr)
    if AmmoD == 1 then
        if game.Players.LocalPlayer.Name ~= plr.Parent.Name then
            game.Workspace:FindFirstChild(plr.Parent.Name).Humanoid:TakeDamage(3)
    end
    end
    AmmoD = AmmoD - 1
end))

Hope this helps,

Tweakified

0
I put in. Got a few errors but fixed them and it doesn't damage myself. But it doesn't damage others either. Any suggestions? AverageMonkey112 0 — 4y
Ad

Answer this question