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

[SOLVED] Attack doesn't fire after another attack?

Asked by
bluzorro 417 Moderation Voter
4 years ago
Edited 4 years ago

Hello. I'm making a fireball that seems to work fine, but the problem is that it won't get cast after I cast an attack and hold it to the max.

repeat wait(1) until game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local char = player.Character or player.CharacterAdded:Wait()

local UIS = game:GetService("UserInputService")
local debounce = false
local holding = false

local root = char:WaitForChild("HumanoidRootPart")
local hum = char:WaitForChild("Humanoid")

local sizeX, sizeY = 2.2, 2.2
local maxSizeX, maxSizeY = 5.5, 5.5

local circle = game.ReplicatedStorage.Circles:WaitForChild("Circle")

local cast = Instance.new("Animation")
cast.AnimationId = "rbxassetid://4716165640"
local castAnim = hum:LoadAnimation(cast)

game:GetService("ContentProvider"):PreloadAsync({cast})

script.Parent.Equipped:Connect(function()
    UIS.InputBegan:Connect(function(key, gpe)
        if gpe then return end

        if key.KeyCode == Enum.KeyCode.Q and not debounce and not holding and hum.PlatformStand ~= true then
            debounce = true
            holding = true

            castAnim:Play()

            castAnim:GetMarkerReachedSignal("Pause"):Connect(function()
                castAnim:AdjustSpeed(0)
            end)

            circle.Parent = game.Workspace
            circle.CFrame = root.CFrame * CFrame.new(0, 0, -3.5)

            spawn(function()
                while holding do
                    sizeX = sizeX + 0.05
                    sizeY = sizeY + 0.05

                    print("sizex ", sizeX)

                    circle.CFrame = root.CFrame * CFrame.new(0, 0, -3.5)
                    circle.Size = Vector3.new(sizeX, sizeY, 0.1)


                    if holding and sizeX >= maxSizeX then
                        game.ReplicatedStorage.Remotes.InitializeAttack:FireServer(sizeX, sizeY)
                        castAnim:Stop()
                        break
                    elseif not holding and sizeX >= 2.5 then
                        game.ReplicatedStorage.Remotes.InitializeAttack:FireServer(sizeX, sizeY)
                        castAnim:Stop()
                        break
                    elseif not holding and sizeX <= 2.5 then
                        castAnim:Stop()
                        break                       
                    end

                    wait()
                end

                sizeX = 2.2
                sizeY = 2.2
            end)

            spawn(aim)

            spawn(function()
                wait()
                debounce = false
            end)                
        end
    end)

    UIS.InputEnded:Connect(function(key, gpe)
        if gpe then return end

        if key.KeyCode == Enum.KeyCode.Q and holding and not debounce and sizeX > 2.5 then
            debounce = true
            holding = false

            castAnim:Stop()
            game.ReplicatedStorage.Remotes.InitializeAttack:FireServer(sizeX, sizeY)

            spawn(function()
                wait(1)
                debounce = false
            end)
        end
    end)
end)

local bodyPosition = Instance.new("BodyPosition")
bodyPosition.MaxForce = Vector3.new(100000, 100000, 100000)
bodyPosition.P = 100000
bodyPosition.D = 500
bodyPosition.Parent = char

local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)
bodyGyro.P = 400000
bodyGyro.D = 500
bodyGyro.Parent = char

function aim()
    bodyPosition.Parent = root
    bodyPosition.Position = root.Position
    bodyGyro.Parent = root
    hum.PlatformStand = true

    while true do
        if holding then
            bodyGyro.CFrame = CFrame.new(root.Position, mouse.Hit.p)
        end

        if circle.Parent == game.ReplicatedStorage:WaitForChild("Circles") then
            break
        elseif not holding and sizeX < 2.5 then
            circle.Parent = game.ReplicatedStorage.Circles
            break
        end

        game:GetService("RunService").Heartbeat:Wait()
    end

    wait(0.5)
    root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, math.rad(root.Orientation.Y), 0)
    bodyPosition.Parent = char
    bodyGyro.Parent = char
    hum.PlatformStand = false
end
local projectiles = game.ServerStorage:WaitForChild("Projectiles")
local circle = game.ReplicatedStorage:WaitForChild("Circles").Circle

local debounce = false
local cooldown = false

game.ReplicatedStorage.Remotes.InitializeAttack.OnServerEvent:Connect(function(player, sizeX, sizeY)
    if not cooldown then
        cooldown = true

        local char = player.Character or player.CharacterAdded:Wait()
        local hum = char:WaitForChild("Humanoid")
        local root = char:WaitForChild("HumanoidRootPart")
        local database = player:WaitForChild("Database")
        local damage = math.floor(database.HP.Value / 3)
        local fireball = projectiles.Fireball:Clone()

        circle.Parent = game.Workspace
        circle.Orientation = root.Orientation
        circle.CFrame = root.CFrame * CFrame.new(0, 0, -3.5)
        circle.Size = Vector3.new(sizeX, sizeY, 0.1)

        fireball.Parent = game.Workspace
        fireball.CFrame = circle.CFrame * CFrame.new(0, 0, -2)

        local bodyVelocity = Instance.new("BodyVelocity")
        bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bodyVelocity.Velocity = circle.CFrame.lookVector * 60
        bodyVelocity.Parent = fireball

        database.Level.XP.Value = database.Level.XP.Value + 15
        database.MagicLevel.MagicXP.Value = database.MagicLevel.MagicXP.Value + 15

        for i = sizeX, 2.2, -0.2 do
            circle.Size = Vector3.new(i, i, 0.1)
            game:GetService("RunService").Heartbeat:Wait()
        end

        sizeX = 2.2
        sizeY = 2.2
        print("SizeX ", sizeX)
        circle.Size = Vector3.new(sizeX, sizeY, 0.1)
        circle.Parent = game.ReplicatedStorage.Circles

        fireball.Touched:Connect(function(hit)
            if hit.Name ~= "Dawn's Birth" then  
                local explosion = game.ServerStorage:WaitForChild("Misc").Explosion:Clone()         
                explosion.CFrame = fireball.CFrame
                explosion.Parent = game.Workspace

                fireball:Destroy()

                if hit.Parent:FindFirstChild("Humanoid") then
                    hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
                end

                spawn(function()
                    for i = 180, 0, -2 do
                        explosion.Orientation = Vector3.new(0, i, 0)
                        game:GetService("RunService").Heartbeat:Wait()
                    end                 
                end)

                spawn(function()
                    for i = 0.4, 1, 0.01 do
                        explosion.Transparency = i
                        game:GetService("RunService").Heartbeat:Wait()
                    end

                    explosion.Transparency = 1
                end)

                for i = 2, 9, 0.1 do
                    explosion.BlastMesh.Scale = Vector3.new(i, 2, i)
                    game:GetService("RunService").Heartbeat:Wait() 
                end

                explosion:Destroy()
            end
        end)

        local co = coroutine.create(function()
            pcall(function()
                wait(5)
                fireball:Destroy()
            end)
        end)

        coroutine.resume(co)

        wait(1)
        cooldown = false            
    end
end)

As long as I don't hold the button until the attack gets released, I can fire as many attacks afterward, but I can't fire any more attacks if I hold one attack to the max.

0
Nevermind, fixed it. It was because of the holding variable not turning to false although the attack was cast. bluzorro 417 — 4y

Answer this question