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