I am trying to get a cooldown to use as a wait, yes I’m not using task.wait currently, I’ll fix that later, but it keeps popping up the error
DecodedAttack is not a valid member of ModuleScript "ServerScriptService.Attack-Related_Scripts.ClassModules.Peasant"
for [DecodedAttack] in
wait(require(game:GetService("ServerScriptService")["Attack-Related_Scripts"].ClassModules[ClassKey][DecodedAttack][DecodedAttack.."_Cooldown"]))
The original function is below.
Script
local function AttackAnimation(player, ID, Class, Attack)
local animator = player.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = HttpService:JSONDecode(ID)
local AnimationLoaded = animator:LoadAnimation(Animation)
AnimationLoaded:Play()
AnimationLoaded.Priority = 1
local ClassKey = HttpService:JSONDecode(Class)
local DecodedAttack = HttpService:JSONDecode(Attack)
print(DecodedAttack)
wait(require(game:GetService("ServerScriptService")["Attack-Related_Scripts"].ClassModules[ClassKey].DecodedAttack[DecodedAttack.."_Cooldown"]))
Module Script
local Peasant = {
Attack1 = {
Attack1_AnimationId = "rbxassetid://6550920054", --Attack1 Animation Id
Attack1_Damage = 10, -- Attack Damage
Attack1_StatDamage = 0.1,
Attack1_Cooldown = 1.5
};
Attack2 = {
Attack2_AnimationId = "rbxassetid://7070234299",
Attack2_Damage = 15,
Attack2_StatDamage = 0.3,
Attack2_Cooldown = 5
};
Attack3 = { Attack3_AnimationId = "rbxassetid://7071810900",
Attack3_Damage = 7,
Attack3_Ticks = 2,
Attack3_TBT = 0.5, --Time Between Ticks
Attack3_StatDamage = 0.2,
Attack3_Cooldown = 4
}
}
return Peasant
I have tried testing out a few things like using [ClassKey] again since the module script and table of Decoded Attack have the same name and have ClassKey twice for the same reason.