How to not damage myself

the title says it all, i dont know how to not take damage, its a part that spawns on my character that isint supposed to take damage on the player that spawns it.

this is the code i think is the problem

		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health -= 15
				wait()					
			end
		end)

this is the full script

game:GetService("ReplicatedStorage").Remotes.ExtraRemote.OnServerEvent:Connect(function(player)
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://10181596993"
	local AT = player.Character.Humanoid:LoadAnimation(animation)
	AT.Looped = true
	AT:play()
	game:GetService("ReplicatedStorage").Remotes.GumPistol.OnServerEvent:Connect(function(player,mousePos)
		local part = Instance.new("Part")
		AT:Stop()
		wait()
		local animation2 = Instance.new("Animation")
		animation2.AnimationId = "rbxassetid://10182139703"
		local AT2 = player.Character.Humanoid:LoadAnimation(animation2)
		AT2.Looped = false
		AT2:play()
		local soundeffect = Instance.new("Sound")
		soundeffect.SoundId = "rbxassetid://137463821"
		soundeffect.Parent = player.Character.PrimaryPart
		soundeffect:Play()
		local mouse = player:GetMouse()
		local TInfo = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
		local TS = game:GetService("TweenService")
		part.Size = Vector3.new(1,1,12)
		part.Parent = workspace
		part.CanCollide = false
		part.Anchored = true
		part.Transparency = 0.2
		part.Color = Color3.new(1, 0.85098, 0.745098)
		part.Material = Enum.Material.SmoothPlastic
		wait(.1)
		local RootPos, MousePos = part.Position, mousePos
		part.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, MousePos.Y, MousePos.Z))
		part.CFrame = player.Character["Right Arm"].CFrame * CFrame.new(0,0,0)
		player.Character["Right Arm"].Transparency = 1
		local tweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(0.45, Enum.EasingStyle.Linear)
		local tween2 = tweenService:Create(part,tweenInfo,{Transparency = 0.8})
		local tweenInfo2 = TweenInfo.new(3.5, Enum.EasingStyle.Linear)
		local tween3 = tweenService:Create(part,tweenInfo2,{Size = Vector3.new(1,1,100)}):Play()
		part.Anchored = false
		local RootPos, MousePos = part.Position, mousePos
		part.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, MousePos.Y, MousePos.Z))
		local BodyVelocity = Instance.new("BodyVelocity",part)
		BodyVelocity.MaxForce = Vector3.new(100000,100000,100000)
		BodyVelocity.Velocity = CFrame.new((player.Character["Right Arm"].CFrame * CFrame.new(0,1.5,-5)).Position,mousePos).LookVector * 125
		tween2:Play()
		tween2.Completed:Connect(function()
			BodyVelocity:Destroy()
			local tweenService = game:GetService("TweenService")
			local tweenInfo2 = TweenInfo.new(0.2, Enum.EasingStyle.Linear)
			local tween = tweenService:Create(part, tweenInfo2, {Position = player.Character["Right Arm"].Position})
			tweenService:Create(part,tweenInfo,{Transparency = 0}):Play()
			part.Transparency = 0.8
			tween:Play()
			tween.Completed:Connect(function()
				player.Character["Right Arm"].Transparency = 0
				local sound2 = Instance.new("Sound")
				sound2.SoundId = "rbxassetid://10223776381"
				sound2.Parent = player.Character.HumanoidRootPart
				sound2.Volume = 0.5
				sound2:Play()
				part:Destroy()
				local animation3 = Instance.new("Animation")
				animation3.AnimationId = "rbxassetid://10212726203"
				local AT3 = player.Character.Humanoid:LoadAnimation(animation3)
				AT3.Looped = false
				AT3:play()		
			end)
		end)
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				hit.Parent.Humanoid.Health -= 15
				wait()					
			end
		end)
	end)
end)

and this is the local

local UIS = game:GetService("UserInputService")
local Controls = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule")):GetControls()
local Equipped = false
local DB1 = false
local DB2 = false
local DB3 = false
local DB4 = false
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local Root = player.Character.HumanoidRootPart
local mousepoint = false
local mousepoint2 = false

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if Equipped == true then
			if DB1 == false then
				DB1 = true
				game:GetService("ReplicatedStorage").Remotes.ExtraRemote:FireServer()
				Controls:Disable()
				player.Character.HumanoidRootPart.Anchored = true
				mousepoint = true
				while mousepoint == true do
					wait()
					local RootPos, MousePos = Root.Position, mouse.Hit.Position
					Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, MousePos.Y, MousePos.Z))
				end
			end
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if Equipped == true then
			if DB2 == false then
				DB2 = true
				wait()
				game:GetService("ReplicatedStorage").Remotes.GumPistol:FireServer(mouse.Hit.Position, player)
				mousepoint = false
				wait(.5)
				player.Character.HumanoidRootPart.Anchored = false
				Controls:Enable()
				wait(3)
				DB1 = false
				DB2 = false
			end			
		end
	end
end)

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://10225959868"
local AT = player.Character.Humanoid:LoadAnimation(animation)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if Equipped == true then
			if DB3 == false then
				DB3 = true
				wait()
				player.Character.Humanoid.WalkSpeed = 3
				game:GetService("ReplicatedStorage").Remotes.GumGatling:FireServer(mouse.Hit.Position, player)
				AT.Looped = true
				AT:play()
				mousepoint2 = true
				while mousepoint2 == true do
					wait()
					local RootPos, MousePos = Root.Position, mouse.Hit.Position
					Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
				end
			end
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then
		if Equipped == true then
			if DB4 == false then
				DB4 = true
				game:GetService("ReplicatedStorage").Remotes.StopGumGatling:FireServer()
				player.Character.Humanoid.WalkSpeed = 12
				mousepoint2 = false
				AT:Stop()
				wait(3)
				DB4 = false
				DB3 = false
			end
		end
	end
end)

script.Parent.Equipped:Connect(function()
	Equipped = true
	script.Parent.Unequipped:Connect(function()
		Equipped = false
	end)
end)

You could add a String value called “PlayerOwns”
When the Player creates it make the PlayerOwns value equal to the Player name (That created it)
Once the Player touches the part check if the Player that touched it name isn’t the the PlayerOwns value

For example

local  Part = Instance.new("Part")
local PlayerOwns = Instance.new("StringValue")
PlayerOwns.Name = "PlayerOwns"
PlayerOwns.Value = Player.Name

Part.Touched:Connect(function(hit)
-- Check if the player who touched it isn't equal to the PlayerOwns value
end)

You can detect if hit:IsDescendantOf(player) is false before damaging.

i tried

		local PlayerOwns = Instance.new("StringValue")
		PlayerOwns.Name = "PlayerOwns"
		PlayerOwns.Value = player.Name
		part.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				if not PlayerOwns.Value then
					hit.Parent.Humanoid.Health -= 15
					wait()						
				end				
			end

and when i tried that it didnt do damage to anything

Did you try my solution? I think that might work.

Also, PlayerOwns must be parented to the player’s character, and you must be using FindFirstChild.

yes i tried but it still took damage on myself

Sorry I messed up on my first post.

Try this instead:
if hit:IsDescendantOf(player.Character) then return end