Hey yall, so I have an issue with my Fireball ability which I never had before.
Whenever I throw my Fireball, it explodes instantly, when it’s supposed to explode when it hits something.
This is my script btw
if skillName == "Fireball" then
local hasExploded = false
local isHit = false
combatModule.PlayAnimation(humanoid, skillConfig:WaitForChild("AnimationID").Value)
combatModule.CharacterFaceCursor(humanoidRootPart, mousePosition)
humanoid.WalkSpeed = 0
wait(0.5)
humanoid.WalkSpeed = 20
local fireball = spells:WaitForChild("Fireball"):Clone()
fireball.Parent = vfx
game:GetService("Debris"):AddItem(fireball, 5)
fireball.CFrame = humanoidRootPart.CFrame + humanoidRootPart.CFrame.LookVector * 10
local distance = (fireball.Position - mousePosition).Magnitude
local speed = 0.2
local tweenTime = speed * distance / 15
local sound = sounds:WaitForChild(skillName):Clone()
sound.Parent = fireball
sound:Play()
local rayOrigin = humanoidRootPart.Position
local rayDirection = mousePosition
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character, fireball}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
local fireballTween = ts:Create(fireball, TweenInfo.new(tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Position = raycastResult.Position})
fireballTween:Play()
local function ExplosionEffect()
if not hasExploded then
hasExploded = true
fireballTween:Pause()
combatModule.Debris(character, fireball.Position, 20, 5, Vector3.new(math.random(1,1.15), math.random(1,1.5), math.random(1,1.15)), 3, false, "Fire")
rs:WaitForChild("Events"):WaitForChild("ShakeCamera"):FireAllClients(200, 0.1)
ts:Create(fireball:WaitForChild("PointLight"), TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Brightness = 0}):Play()
ts:Create(fireball, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Size = fireball.Size + Vector3.new(2,2,2), Transparency = 1}):Play()
for i, v in pairs(fireball:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = false
end
end
for i, v in pairs(fireball:WaitForChild("Explosion"):GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit(100)
end
end
wait(0.5)
fireball:Destroy()
end
if raycastResult then
ExplosionEffect()
else
warn("No collision detected.")
end
end
fireballTween.Completed:Connect(ExplosionEffect)
fireball.Touched:Connect(function(hit)
if hit.Parent.Name == character.Name then return end
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:WaitForChild("Shield").Value == false then
if table.find(hits, hit.Parent) then return end
if not table.find(hits, hit.Parent) then
if not isHit then
isHit = true
ExplosionEffect()
combatModule.Hit(player, hit, sounds:WaitForChild("Hit"), values:WaitForChild("DefaultDamage").Value * skillConfig:WaitForChild("DamageMulti").Value)
table.insert(hits, hit.Parent)
end
end
end
end)
end