Bool values in module scripts

I’m trying to create a cooldown bool value when a skill is used, however when I use the skill the cooldown applies for everybody therefore only 1 person can use the skill at a time.

I can provide some parts of the script if needed, but I used a return function because I’m not really experienced with module scripts, if there’s a better way to activate a module script I wouldn’t mind either.

2 Likes

It has to be in ServerStorage if that’s happening.

How do you make a separate bool value? I’m talking about a true and false statement inside the script

In that case you’d need a table to hold the values of each player.

local Cooldowns = {}

local function Skill() --Example skill function.
	if Cooldowns[Player] then return end --Ignore if player is in a cooldown.
	Cooldowns[Player] = true --Start the cooldown for the player.
	--Perform the skill.
	task.wait(3) --Wait for the length of the cooldown.
	Cooldowns[Player] = nil
end

I was going to do this previously, but I was seeing if theres a simpler method, but I’ll use this instead thanks.

-- How long cool down lasts
local cooldown_time = 3

-- Function
local function Skill(player: Player)
    -- Using attributes, but you can also use tables, but REMOVE PLAYER KEY FROM TABLE WHEN PLAYER LEAVES GAME (when using tables)
    local last_time = player:GetAttribute("SkillCooldown") or 0
    if os.clock() - last_time >= 3 then print("Init Skill") end
end

I take this back your method is fine

They’re removed from the table after three seconds regardless of if or not they’re still in the game.

1 Like