#How do you make a time limit on start up and a cooldown feature

1 messages · Page 1 of 1 (latest)

bleak cosmos
#

I made an ability for this roblox game but I don't know how to make a time limit function or a cooldown function where you can't use it again

This is the Script under ServerScriptService labeled Deathsperate

    task.wait(1.5)

    local Effect = game.ReplicatedStorage.FireBALL.Attachment:Clone()
    Effect.Parent = data.Character:FindFirstChild("Head")
    Effect.CFrame = Effect.CFrame*CFrame.new(0,-1,0)
    for i,v in pairs(Effect:GetChildren()) do
        v:Emit(10)
    end

    if data.RemoveShirt then
        local shirt = data.Character:FindFirstChild("Shirt")
        if shirt then
            shirt:Destroy()
        end
    end

    if data.RemovePants then
        local pants = data.Character:FindFirstChild("Pants")
        if pants then
            pants:Destroy()
        end
    end

    if data.PantsTemplate then
        local pants = data.Character:FindFirstChild("Pants")
        if pants then
            pants.ShirtTemplate = data.PantsTemplate
        end
    end

    if data.RemoveEffect then
        for _, child in pairs(Effect:GetDescendants()) do
            if child:IsA("BasePart") then
                child:Destroy()
            end
        end
        Effect:Destroy()
    end
end)```
river pecanBOT
#

studio** You are now Level 6! **studio

bleak cosmos
#

And this is the local script under StarterCharacterScripts

local RPS = game:GetService("ReplicatedStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local Cooldown = false
local player = game.Players.LocalPlayer
local Character  = player.Character or player.CharacterAdded:Wait()

local camera = workspace.CurrentCamera
local module = require(ReplicatedStorage.CameraShaker)
local Shaker = module.new(Enum.RenderPriority.Camera.Value,function(shakeCFrame)
    camera.CFrame = camera.CFrame * shakeCFrame
end)
Shaker:Start()

UIS.InputBegan:Connect(function(input,gpe)
    if gpe then return end
    if input.KeyCode == Enum.KeyCode.F and Cooldown == false  then
        Cooldown = true

        Character.Humanoid.WalkSpeed = 0
        Character.Humanoid.JumpHeight = 0
        Character.Humanoid.AutoRotate = false
        local Animation = Instance.new("Animation")
        Animation.AnimationId = "rbxassetid://129244296050535"

        local Track = player.Character.Humanoid:LoadAnimation(Animation)
        Track:Play()

        local pantsTemplate = "rbxassetid://256076237"
        local data = {
            ["Character"] = player.Character,
            ["Action"] = "Fire",
            ["RemoveShirt"] = true,
            ["RemovePants"] = false,
            ["PantsTemplate"] = pantsTemplate,
            ["RemoveEffect"] = true
        }

        game.ReplicatedStorage.RemoteEvent:FireServer(data)

        task.wait(1.5)
        Shaker:ShakeOnce(20,20,.2,.4)
        task.wait(3)
        Character.Humanoid.WalkSpeed = 20
        Character.Humanoid.JumpHeight = 10
        Character.Humanoid.Health += 50
        Character.Humanoid.AutoRotate = true

        task.wait(60)
        Cooldown = false
    end
end)```
#

Also one more thing

#

why won't the pants change when used?

summer bridge
#

if its just set it to true

#

then wait an amount of time after you do the ability then set the variable to false again

bleak cosmos
#

wdym

summer bridge
#

smth like this

local debounce = false

if debounce == false then
  debounce = true
  -- do the ability here
  
  task.wait(5) -- cooldown time
  debounce = false
end
bleak cosmos
#

also I’m doing uhh

#

wer

#

I’m doing a 60 second wait until the ability turns off

#

and 5 minute wait to use it again

#

i gotta get better at scripting

summer bridge
#

does this not do anything? because it looks like there is already a cooldown system there

bleak cosmos
#

well

#

there is a cooldown function

#

but it doesn’t take off the effects

#

and you can do it again layering the effects/vfx of the “fireball”

#

this is what it does

#

don't mind the vfx

craggy rock
#
local RPS = game:GetService("ReplicatedStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local Cooldown = false
local player = game.Players.LocalPlayer
local Character  = player.Character or player.CharacterAdded:Wait()

local camera = workspace.CurrentCamera
local module = require(ReplicatedStorage.CameraShaker)
local Shaker = module.new(Enum.RenderPriority.Camera.Value,function(shakeCFrame)
    camera.CFrame = camera.CFrame * shakeCFrame
end)
Shaker:Start()

UIS.InputBegan:Connect(function(input,gpe)
    if gpe or Cooldown then return end
    if input.KeyCode == Enum.KeyCode.F then
        Cooldown = true

        Character.Humanoid.WalkSpeed = 0
        Character.Humanoid.JumpHeight = 0
        Character.Humanoid.AutoRotate = false
        local Animation = Instance.new("Animation")
        Animation.AnimationId = "rbxassetid://129244296050535"

        local Track = player.Character.Humanoid:LoadAnimation(Animation)
        Track:Play()

        local pantsTemplate = "rbxassetid://256076237"
        local data = {
            ["Character"] = player.Character,
            ["Action"] = "Fire",
            ["RemoveShirt"] = true,
            ["RemovePants"] = false,
            ["PantsTemplate"] = pantsTemplate,
            ["RemoveEffect"] = true
        }

        game.ReplicatedStorage.RemoteEvent:FireServer(data)

        task.wait(1.5)
        Shaker:ShakeOnce(20,20,.2,.4)
        task.wait(3)
        Character.Humanoid.WalkSpeed = 20
        Character.Humanoid.JumpHeight = 10
        Character.Humanoid.Health += 50
        Character.Humanoid.AutoRotate = true

        task.wait(60)
        Cooldown = false
    end
end)```
#

here

#

all I did is

#

when InputBegan

#

I did if Cooldown then return end

#

I also removed the and Cooldown == false

#

cuz the code is already checking if cooldown is true or not

#

so its unecassary

#

let me explain it for you

#

heres a code

local Debounce = false
local UIS = ..

UIS.InputBegan:Connect(function(Input,gpe,)
if Cooldown or gpe then return end

if Input.KeyCode == Enum.KeyCode.F then
Cooldown = true

end

task.wait(5)
Cooldown = true
end)```
#

this basically

#

whenever u press a key

#

it first checks if cooldown is true or gpe

#

if one of them is true u return the code to nil so basically it wont run

#

but if cooldown is not true u then can run the code and if keycode is F u set cooldown to true

#

so now that Cooldown is true u cant press again because the code returns when cooldown is true

#

and after waiting 5 sec u put it back to false

#

and then u can press again

bleak cosmos
#

okay

#

let me try

bleak cosmos
#

I put this at the end of local script

#

and it didn't work

#

as in the ability itself didn't work

craggy rock
#

use this code

#

local UIS = game:GetService("UserInputService")
local RPS = game:GetService("ReplicatedStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local Cooldown = false
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

local camera = workspace.CurrentCamera
local module = require(ReplicatedStorage.CameraShaker)
local Shaker = module.new(Enum.RenderPriority.Camera.Value,function(shakeCFrame)
camera.CFrame = camera.CFrame * shakeCFrame
end)
Shaker:Start()

UIS.InputBegan:Connect(function(input,gpe)
if gpe or Cooldown then return end
if input.KeyCode == Enum.KeyCode.F then
Cooldown = true

    Character.Humanoid.WalkSpeed = 0
    Character.Humanoid.JumpHeight = 0
    Character.Humanoid.AutoRotate = false
    local Animation = Instance.new("Animation")
    Animation.AnimationId = "rbxassetid://129244296050535"

    local Track = player.Character.Humanoid:LoadAnimation(Animation)
    Track:Play()

    local pantsTemplate = "rbxassetid://256076237"
    local data = {
        ["Character"] = player.Character,
        ["Action"] = "Fire",
        ["RemoveShirt"] = true,
        ["RemovePants"] = false,
        ["PantsTemplate"] = pantsTemplate,
        ["RemoveEffect"] = true
    }

    game.ReplicatedStorage.RemoteEvent:FireServer(data)

    task.wait(1.5)
    Shaker:ShakeOnce(20,20,.2,.4)
    task.wait(3)
    Character.Humanoid.WalkSpeed = 20
    Character.Humanoid.JumpHeight = 10
    Character.Humanoid.Health += 50
    Character.Humanoid.AutoRotate = true

    task.wait(60)
    Cooldown = false
end

end)

#

this will work

#

and then compare ur old one with this

#

youll see the mistake

bleak cosmos
#

it didn't work

#

it didn't turn off in 60 seconds

worldly obsidian
#

Idk bro learn scripting

bleak cosmos
worldly obsidian