Hey.
So I have a problem with my fireball where it would destroy its-self and give damage to when almost in contact (close to) with the player (npc).
I want to know why this happens?
Here is a video of what I am talking about:
robloxapp-20221009-1539455.wmv (333.5 KB)
Code:
game.ReplicatedStorage.HadokenEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:WaitForChild('Humanoid')
local clonedPart = game.ReplicatedStorage.HadokenPart:Clone()
clonedPart.Parent = workspace
clonedPart:SetNetworkOwner(character)
clonedPart.CFrame = character:WaitForChild('HumanoidRootPart').CFrame
local bodyVelocity = Instance.new('BodyVelocity', clonedPart)
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = Vector3.new(0,0,-40) -- (clonedPart.CFrame.LookVector * 40) --
game.Debris:AddItem(clonedPart, 4)
clonedPart.Touched:Connect(function(hit)
local parentofhit = hit.Parent
local humanoid = parentofhit:FindFirstChild("Humanoid")
if parentofhit == player.Character then return end
if not humanoid then return end
if humanoid.Health == 0 then return end
if humanoid then
humanoid:TakeDamage(10)
clonedPart:Destroy()
end
end)
end)
If I am honest, I can not find any problems within this code. Help is appreciated.