i’m currently making a Debuff system and i’m having trouble with making the Petrified one
what i want it to do, is disable all the abilities that the player has, and after the specified duration, re-enable them again
the disabling and re-activating are working perfectly, however the waiting for the re-enabling is kind of tripping me
this is the code for it
coroutine.create(function ()
for _, abilities in pairs(PlayerData.CurrentAbilities) do
PetrifiedEvent:FireClient(player, abilities)
UI:LockAbility(player, abilities.Name)
task.wait(0.01)
end
task.wait(duration)
--task.spawn(function ()
for _, abilities in pairs(PlayerData.CurrentAbilities) do
Unpetrify:FireClient(player, abilities, PlayerData.Character)
UI:UnlockAbility(player, abilities.Name)
task.wait(0.01)
end
--end)
end)
if i put a waiting function on the main DebuffModule, it’s just gonna add additional time and i don’t want that
What is your ‘duration’ variable set to? And why did you put it into a coroutine? Coroutine is usually used for loading stuff. Also i’m pretty sure you should also use coroutine.resume() if you’re gonna be using a coroutine.
Could you show me both entire scripts?
Is your coroutine function able to access said variable? Are you sure the variable’s value isn’t getting reset somehow?
local UI = require(game:GetService("ReplicatedStorage").UI)
local GameDataManager = require(game:GetService("ReplicatedStorage").GameDataManager)
local Debuffs = require(script.Debuffs)
local module = {}
function module:RemoveDebuff(player: Player, name)
local PlayerData = GameDataManager:GetPlayerData(player)
if not PlayerData["Debuffs"][name] then return warn("player selected does not have debuff") end
Debuffs[name](player, 0, 0)
PlayerData["Debuffs"][name] = nil
UI:RemoveDebuff(player, name)
end
function module:GiveDebuff(player: Player, name, amount, duration)
local PlayerData = GameDataManager:GetPlayerData(player)
local DebuffClientEvent = game:GetService("ReplicatedStorage").Events.UpdateDebuffClient
PlayerData["Debuffs"][name] = {
Amount = amount,
Duration = duration
}
DebuffClientEvent:FireClient(player, PlayerData["Debuffs"])
UI:CreateDebuff(player, name, amount, duration)
Debuffs[name](player, amount, duration)
--task.wait(duration)
PlayerData["Debuffs"][name] = nil
print(PlayerData["Debuffs"])
Debuffs[name](player, 0, 0)
DebuffClientEvent:FireClient(player, PlayerData["Debuffs"])
end
return module
the Debuffs module script, containing all the Debuffs needed for the main module
local GameDataManager = require(game:GetService("ReplicatedStorage").GameDataManager)
local module = {
Slowness = function (player, amount, duration)
local PlayerData = GameDataManager:GetPlayerData(player)
local character = player.Character
local humanoid = character.Humanoid
humanoid.WalkSpeed = PlayerData["GameInfo"].OriginalWalkSpeed - amount
end,
Petrified = function(player, amount, duration)
local UI = require(game:GetService("ReplicatedStorage").UI)
local PlayerData = GameDataManager:GetPlayerData(player)
local PetrifiedEvent = game:GetService("ReplicatedStorage").Events.Petrified
local Unpetrify = game:GetService("ReplicatedStorage").Events.Unpetrify
local thing = coroutine.create(function ()
for _, abilities in pairs(PlayerData.CurrentAbilities) do
PetrifiedEvent:FireClient(player, abilities)
UI:LockAbility(player, abilities.Name)
task.wait(0.01)
end
task.wait(duration)
--task.spawn(function ()
for _, abilities in pairs(PlayerData.CurrentAbilities) do
Unpetrify:FireClient(player, abilities, PlayerData.Character)
UI:UnlockAbility(player, abilities.Name)
task.wait(0.01)
end
--end)
end)
coroutine.resume(thing)
end,
}
return module
From what i’m seeing your duration variable is not being set to anything. All i can see concerning it is that you’re setting it to ‘0’ (i’m not sure if youre actually doing that but it seems like you are) at:
Line 35 of the DebuffModule script
Debuffs[name](player, 0, 0)
If it’s set to 0 then it’s not gonna wait, instead it should be something like
Debuffs[name](player, 0, 1)
What number value is it being set to though? “duration” is a variable, not a number value, and if you want it to work you need to set the duration variable to a number value.
Is it being randomized? If so at what line? Because if it’s any number it can range from 0 to waiting hours.
Know that task.wait(1) = wait 1 second. So if it’s waiting for 120 it’s gonna be waiting for 2 minutes and so on.
it’s being set when a command using the CMDR bar is ran
this is the module script of the structure for the command
return {
Name = "give-debuff",
Description = "Gives a debuff to a player",
Args = {
{
Type = "player",
Name = "Player",
Description = "The player affected with the debuff"
},
{
Type = "debuff",
Name = "Debuff",
Description = "The debuff to give to the player"
},
{
Type = "number",
Name = "Amount",
Description = "The amount of the debuff"
},
{
Type = "number",
Name = "Duration",
Description = "The duration of the debuff"
}
}
}
and this is the server module script
return function (context, player, debuff, amount, duration)
local DebuffModule = require(game:GetService("ReplicatedStorage").DebuffModule)
DebuffModule:GiveDebuff(player, debuff, amount, duration)
end