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

Could anybody help me add a cooldown into my client sided scipt?

Asked by
Dec_ade 47
4 years ago
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local debounce = false

local Keybind = script:WaitForChild("Keybind").Value

local BodyGyroTime = false

local AnimationsFolder = game.ReplicatedStorage.Animations

local HoldAnim = AnimationsFolder.Hold
local ReleaseAnim = AnimationsFolder.Release

local HoldAnimLoader
local ReleaseAnimLoader

local BG
local BP

UserInputService.InputBegan:Connect(function(Input, IsTyping)
    if not IsTyping then
        if Input.KeyCode == Enum.KeyCode[Keybind] then

        --- Forces
        BodyGyroTime = true

        HoldAnimLoader = Player.Character:WaitForChild("Humanoid"):LoadAnimation(HoldAnim)
        HoldAnimLoader:Play()



        BG = Instance.new("BodyGyro")
        BG.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
        BG.P = 15000
        BG.Name = "FireBallGyro"
        BG.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, Mouse.Hit.Position)
        BG.Parent = Player.Character:FindFirstChild("HumanoidRootPart")

        BP = Instance.new("BodyPosition",Player.Character:WaitForChild("HumanoidRootPart"))
        BP.D = 1250
        BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
        BP.P = 10000
        BP.Position = Player.Character:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,0.1,0)


        game.ReplicatedStorage.Flame:FireServer("FireBallHolding")



         spawn(function()       
            while BodyGyroTime == true do
                   wait(0.01)
                   BG.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, Mouse.Hit.Position)
                end
            end)
        end
    end
end)

UserInputService.InputEnded:Connect(function(Input, IsTyping)
    if not IsTyping then
        if Input.KeyCode == Enum.KeyCode[Keybind] then
            HoldAnimLoader:Stop()

            ReleaseAnimLoader = Player.Character:WaitForChild("Humanoid"):LoadAnimation(ReleaseAnim)
            ReleaseAnimLoader:Play()
            wait(ReleaseAnimLoader.Length)

            game.ReplicatedStorage.Flame:FireServer("FireBallFired",Mouse.Hit.Position)
            BodyGyroTime = false
            local BGDestroy = Player.Character.HumanoidRootPart:WaitForChild("FireBallGyro")
            BGDestroy:Destroy()
            local BPDestroy = Player.Character.HumanoidRootPart:WaitForChild("BodyPosition")
            BPDestroy:Destroy()
        end
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Well what I like to do when I want to add a cooldown to a script is very simple and stupid, but what I do is

Script.Disabled = true
wait("the amount of cooldown time u want")
Script.Disabled = false

and so so so simple and it just works

Ad

Answer this question