✓ Accepted answer
Some Fixes/Suggestions
You should use a for loop to perform professional decremental iteration. It is also suggestion you use :GetPropertyChangedSignal() to properly hone down on a property of an Instance changing. Your original code will run the while loop if any aspect of the affiliated instance changes, E.g. it's Name.
Why is it not working?
You allocated AttackerCooldown‘s Value as a constant, meaning it won’t actually actively modify the ValueObject, but the variable instead. Anytime you wish to assign something to a given property, you must define the Property, you cannot declare a pathway to it.
On a final note, calling the code above upon a .Changed signal will cause the signal to fire repeatedly as the pure purpose of the scope is to modify the affiliated Instance. Instead-—as provided by personal conversation of the original-poster—attach the signal to the Attack ValueObject so you can run the cool-down upon Attacker becoming true.
local Player = game.Players:GetPlayerFromCharacter(script.Parent)
local Attacker = Player:WaitForChild("Attacker")
local AttackerCooldown = Player:WaitForChild("AttackerCooldown")
local function CoolDown()
if (Attacker.Value ~= true) then return end
local CoolState = tonumber(AttackerCooldown.Value)
for Cool = CoolState,0,-1 do
AttackerCooldown.Value = Cool
wait(1) end
Attacker.Value = false
end
Player.Attacker:GetPropertyChangedSignal("Value"):Connect(CoolDown)
1 comment
Contact my discord @Ziffixture#0152 so I can speak easier with you if you encounter any issues.