Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my fireball work debris or effects work?

Asked by 1 year ago

For some reason whenever I use my fireball it has errors and doesn't spawn any debris and if it does it doesn't delete it. Can someone help? The problem is mainly in line 138.

local uis = game:GetService('UserInputService')
local rs = game:GetService('ReplicatedStorage')
local ts = game:GetService('TweenService')
local debris = game:GetService('Debris')

local player = game:GetService('Players').LocalPlayer
local mouse = player:GetMouse()
local character = script.Parent
local humanoid = character.Humanoid
local hrp = character.HumanoidRootPart

local remote = rs.Remotes.Attacks.Fire
local ProjectileFBresources = rs.Attacks.ProjectileFireball
local anims = ProjectileFBresources.Animations
local fx = ProjectileFBresources.Fx

local camera = workspace.CurrentCamera
local CameraShaker = require(rs.Modules.CameraShaker)

local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCFrame)
    camera.CFrame = camera.CFrame * shakeCFrame
end)
camShake:Start()

local function rayCast(startPos, endPos, filter, length, obj)
    local params = RaycastParams.new()
    params.FilterType = Enum.RaycastFilterType.Blacklist
    params.IgnoreWater = true
    params.FilterDescendantsInstances = filter

    local result = workspace:Raycast(obj.Position, (endPos - startPos).Unit * length, params)
    if result then
        obj.Position = result.Position
        return false
    else
        obj.Position = (endPos - startPos).Unit * length * startPos
        return true
    end
end

local function fireCharge(data)
    local c = data.c
    local h = c.Humanoid
    local root = c.HumanoidRootPart
    local fireball = fx.Fireball:Clone()
    fireball.Parent = workspace.Fx

    local handFire = fireball.Attach.Fire:Clone()
    handFire.Parent = c.RightHand.RightGripAttachment
    handFire.Enabled = true

    local bodyPos = Instance.new('BodyPosition', root)
    bodyPos.Position = root.Position
    bodyPos.MaxForce = Vector3.new(999999, 999999, 999999)
    bodyPos.P = 1200
    bodyPos.D = 400
    h.JumpHeight = 0

    local floorFire = fx.Fireball:Clone()
    floorFire.CFrame = root.CFrame * CFrame.new(0, -3, 0)
    floorFire.RingAttach.Orientation = Vector3.new(0, 0, 0)
    floorFire.RingAttach.Ring.Enabled = true
    floorFire.Parent = workspace.Fx

    for i = 1, 17 do
        local circleMesh = fx.Circle:Clone()
        circleMesh.Parent = workspace.Fx
        circleMesh.CFrame = c.RightHand.CFrame * CFrame.Angles(math.rad(math.random(0, 180)), math.rad(math.random(0, 180)), math.rad(math.random(0, 180)))
        debris:AddItem(circleMesh, 0.5)
        ts:Create(circleMesh, TweenInfo.new(0.5), {Transparency = 1, Size = Vector3.new(0, 0, 0)}):Play()
        wait(0.1)
    end

    fireball.CFrame = c.HumanoidRootPart.CFrame * CFrame.new(1.5, 0, -5)
    handFire.Enabled = false
    handFire:Destroy()

    local ring = fireball:Clone()
    ring.Parent = workspace.Fx
    ring.CFrame = fireball.CFrame
    ring.RingAttach.Ring:Emit(50)

    h.JumpHeight = 7.2
    bodyPos:Destroy()

    fireball:Destroy()
    floorFire.RingAttach.Ring.Enabled = false
    debris:AddItem(floorFire, 1)
end

local function fireBall(data)
    local c = data.c
    local h = c.Humanoid
    local root = c.HumanoidRootPart

    local fireball = fx.Fireball:Clone()
    fireball.Parent = workspace.Fx
    fireball.CFrame = c.HumanoidRootPart.CFrame * CFrame.new(1.5, 0, -5)
    fireball.Attach.Fire.Enabled = true

    camShake:ShakeOnce(2, 5, 0.2, 0.4)

    local connection
    local count = 0

    connection = game:GetService('RunService').RenderStepped:Connect(function(dt)
        if count > 5 then
            connection:Disconnect()
            fireball.Attach.Fire.Enabled = false
            wait(1)
            fireball:Destroy()
            return
        elseif rayCast(fireball.Position, data.endpoint, {c, workspace.Fx}, 100 * dt, fireball) == false then
            for i = 0, 15 do
                local part = Instance.new('Part', workspace)
                part.Size = Vector3.new(4, math.random(15, 25) / 10, math.random(15, 25) / 10)
                part.Anchored = true
                part.CFrame = CFrame.new(fireball.Position) * CFrame.Angles( 0, math.rad(i * 24), 0) * CFrame.new(0, 0, -8) * CFrame.Angles(math.rad(35), 0, 0)
                part.CanQuery = false
                part.CanCollide = false
                part.CanTouch = false

                local params = RaycastParams.new()
                params.FilterType = Enum.RaycastFilterType.Blacklist
                params.IgnoreWater = true
                params.FilterDescendantsInstances = {c, workspace.Fx}

                local result = workspace:Raycast(part.Position + Vector3.new(0, 2, 0), Vector3.new(0, -10, 0), params)
                if result then
                    part.Position = result.Position
                    part.Material = result.Material
                    part.Color = result.Instance.Color
                end

                if i % 3 < 2 then
                    local fire = fx.Fireball:Clone()
                    fire.Size = Vector3.new(math.random(10, 20) / 10, math.random(10, 20) / 10, math.random(10, 20) / 10)
                    fire.Position = result.Position + Vector3.new(0, 3, 0)
                    fire.Material = result.Material
                    fire.Color = result.Instance.Color
                    fire.Attach.Fire.Enabled = true
                    fire.Attach.Fire.LockedToPart = false
                    fire.Parent = workspace.Fx
                    fire.Anchored = false
                    fire.CanCollide = true

                    local bv = Instance.new('BodyVelocity', fire)
                    bv.Velocity = Vector3.new(math.random(-40, 40), 30, math.random(-40, 40))
                    bv.MaxForce = Vector3.new(99999, 99999, 99999)
                    bv.Name = 'Velocity'

                    debris:AddItem(bv, 0.1)
                    debris:AddItem(fire, 4)

                    spawn(function()
                        wait(2)
                        fire.Attach.Fire.Enabled = false
                        ts:Create(fire, TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Transparency = 1}):Play()
                    end)

                    fire.Transparency = 0
                end

                part.Position = part.Position - Vector3.new(0, 4, 0)
                ts:Create(part, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {Position = part.Position + Vector3.new(0, 4, 0)}):Play()

                spawn(function()
                    debris:AddItem(part, 4)
                    wait(3)
                    ts:Create(part, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position - Vector3.new(0, 4, 0)}):Play()
                end)
            end

            fireball.Attach.Fire.Enabled = false
            fireball.Attach.Explosion:Emit(100)

            camShake:ShakeOnce(2, 5, 0.2, 0.4)
            connection:Disconnect()
            if data.Client == true then
                data.endpoint = fireball.Position
                remote:FireServer('FireballHit', data)
            end
            wait(1)
            fireball:Destroy()
            return
        end
    end)
end

uis.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.Q then
        if mouse.Hit then
            local data = {client = true, c = character}
            local load = humanoid:LoadAnimation(anims.Fireball)
            load:Play()
            debris:AddItem(load, load.Length)
            remote:FireServer('FireCharge', data)
            fireCharge(data)
            data.endpoint = mouse.Hit.Position
            remote:FireServer('Fireball', data)
            fireBall(data)
        end
    end
end)

1 answer

Log in to vote
0
Answered by 1 year ago

On line 138 you you set fire.Position with resect to "Result". But the issue is that Result may not exist in the first place.

On line 129, you do indeed check for result, but you end the if statement before creating the fireball on line 136. I would move all the fireball stuff into the "if result then" statement.

Ad

Answer this question