I made an attack where the player spawns a part in the shape of a ball in front of him. Whenever someone touches that part he gets launched up and receives damage. The problem now is that the player that uses the attack also receives damage when touching the part. So my question is on how I can prevent that from happening.
Damage code:
script.Parent.Touched:Connect(function(hit, Player)
script.Parent:Destroy()
local char = hit.Parent
local hum = char:FindFirstChild(“Humanoid”)
if hum and char then
hum:TakeDamage(20)
local BV = Instance.new(“BodyVelocity”,hit.Parent.HumanoidRootPart)
BV.Velocity = hit.Parent.HumanoidRootPart.CFrame.upVector * 20
BV.MaxForce = Vector3.new(5000000,999999999,5000000)
BV.P = 100
game.Debris:AddItem(BV,.5)
script.Disabled = true
wait(.1)
script:Destroy()
end
end)
When you create the part, make a “Creator” StringValue and store the player’s name. Then when damaging, check if the player’s name is not the creator before applying damage.