Script damaging person that shoots, idk how to make titles

c.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.Damage.Value)
		end
	end)

this script works on rocket launchers but it also damages the person that is shooting. i tried to modify it but… let say it didn’t go well. i tried watching other videos but like always no help so i am asking the dev fourm to help ig.

1 Like

please anyone? it can help me alot since i have tried to fix this for like 1 week now.

just make the shoot part not touch any of the person who is shooting so that when they shoot, it doesn’t hurt them but is like 1 studs away from them if you get what I mean. Also is it FPS or TPS or both?

Check to make sure that “hit” doesn’t belong to the player who fired the rocket launcher’s character.

c.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and not hit.Parent == c.Parent -- change to location of the character model from the player who shot
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.Damage.Value)
		end
	end)

That script being under the assumption that c is attached to the player who shot’s character model

I dont know how to do that. this is my problem.

uhhhh i got an error LOL. i think i should edit the script.

You need to make sure that c.Parent is actually the character model of the person who shot, where is c instantiated from?

uhhhh

local c = Instance.new("Part", script.Parent)

? are you asking me this?

Can you screenshot the explorer where script.Parent of that line of code is

there is literally 47 script.parent stuff, or do you want the one from your script?

When you create the rocket and put this script into the rocket, also put some kind of reference to the character that shot it. People sometimes use ObjectValue objects to keep a reference to the firing player. Then inside the damage script, check to make sure that the hit player is not the same as the firing player.

Inside the rocket creation script:

local creatorTag = Instance.new('ObjectValue')
creatorTag.Name = 'creator'
creatorTag.Value = firingPlayer
creatorTag.Parent = rocket

Inside the damage script:

local playersService = game:GetService('Players')
local creatorTag = c:WaitForChild('creator')
c.Touched:Connect(function(hit)
	if hit and hit.Parent then
		local humanoid = hit.Parent:FindFirstChildOfClass('Humanoid')
		if humanoid and humanoid.Health > 0 then
			local hitPlayer = playersService:GetPlayerFromCharacter(humanoid.Parent)
			if hitPlayer ~= creatorTag.Value then
				humanoid:TakeDamage(script.Parent.Damage.Value)
			end
		end
	end
end)