How do I prevent self damage?

So previosly I made a topic on this area, but I haven’t got the exact answer I want.
I’ve done my research, but it doesn’t work. I tried different methods, but it doesn’t work.
Script:

local Caster = Player.Name

Clone.Touched:Connect(function(Hit)
	local Humanoid = Player.Character:WaitForChild("Humanoid")
	if Caster then return end

	Humanoid.Health -= (FireballDamage)
	Clone.Anchored = true
	Tween:Play()
	wait(1)
Clone:Destroy()
end)
1 Like

This should work.

local Caster = Player.Name

Clone.Touched:Connect(function(Hit)
    if Hit:IsA("Humanoid") and hit.Parent.Name == Caster then 
return; 
elseif Hit:IsA("Humanoid") and not hit.Parent.Name == Caster then
	Hit.Health -= (FireballDamage)
	Clone.Anchored = true
	Tween:Play()
	wait(1)
Clone:Destroy()
end
end)
1 Like

Well, you’re literally only referencing the players humanoid and damaging it. Not sure if that was intended or not.

local Humanoid = Player.Character:WaitForChild("Humanoid")

Note that Hit for a Touched event will always be a Basepart so you don’t have to do if Hit:IsA("Humanoid"). You should however do something like:

local Humanoid = Hit.Parent:FindFirstChild("Humanoid") -- finds a humanoid
if Humanoid then -- you should also check if the Hit.Parent == the player, etc
      -- do logic here
end;

You also don’t need the elseif statement with the return.

For some reason it does not work. When it touches me it doesn’t do anything which is good but when it touches a part than it doesn’t do anything.

I think this will work.

local Caster = Player.Name

Clone.Touched:Connect(function(Hit)
if Hit.Parent:IsA("Humanoid") and not hit.Parent.Parent.Name == Caster then
	Hit.Parent.Health -= (FireballDamage)
	Clone.Anchored = true
	Tween:Play()
	wait(1)
Clone:Destroy()
else return;
end
end)

This will never be true as the Players character parts aren’t stored in the humanoid, so checking Hit.Parent:IsA(“Humanoid”) will do nothing. Also, the players character parts are stored in a model (named after the player), so doing hit.Parent.Parent will only reference workspace (unless there is a manually made part thats parented inside another object, inside the character model).

What type of script is this? 30

The simplest way would probably be to use GetPlayerFromCharacter in that conditional statement

if Players:GetPlayerFromCharacter(Hit:FindFirstAncestorOfClass("Model") or Hit) == Player then return end

(though I would personally wrap the whole function in that condition instead of returning)

Sorry for my late response, but this is a power ability.