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.
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?
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
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.
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)