How would i get the value of the variable in the table corresponding to another object's name?

local cooldowns = {
Ability1 = 0,	
Ability2 = 0,
Ability3 = 0,
Ability4 = 0,
}

for i,button in pairs(GUI.Frame:GetChildren()) do
	if button:IsA("TextButton") then
		button.Activated:Connect(function()
			local event:RemoteEvent = button.Event.Value
			if event then
				if tick() - cooldowns[button.Name]  >= button.CD then -- this is what is wrong
				if char.Humanoid and char.Humanoid.Health <= 0 then warn("dead") return end
				if char:GetAttribute("Sprinting") then warn("doin something") return end
				if char:GetAttribute("Attacking") then return end
				if char:GetAttribute("Blocking") then return end
				if char:GetAttribute("Stunned") then warn("doin something") return end
				if char:GetAttribute("Sheathing") then warn("doin something") return end
				if char:GetAttribute("Stunned") then return end
				if char:GetAttribute("Dodging") then return end
				cooldowns[button.Name] = tick()
				event:FireServer()
			end
			end
		end)
	end
end

the first sample of code is the very simple table i made to store some cooldowns, and in the second, i dont know how to get those cooldowns without writing a long script, when i could make it this short, all the buttons are named the same as their corresponding value in the cooldown table, so the first ability has the cooldown named Ability1, so the button for the first ability is named Ability1, but i dont know how to use that in order to use it in the for loop too easily get it (this is a local script)

SORRY FOR THE BAD WORDING

fixed by adding paranthesis to the subtraction and changing button.CD to button.CD.Value

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.