Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.