I have some gui with a local script that shows moves cooldown, but it only works when testing in studio.
In studio:
In game:
Here’s the script
local player = game.Players.LocalPlayer
local moveframe = script.Parent.MoveFrame
local offset = 0
game.ReplicatedStorage.events.ready.OnClientEvent:Connect(function()
for name, value in player.Character:GetAttributes() do
if name:match("CD") and not name:match("CD2") then --i use CD to get the time that passed since the cooldown started and CD2 for the move's actual cooldown idk if that makes sense
local clonedframe = moveframe:Clone()
clonedframe.Parent = script.Parent
local movename = string.gsub(name, "CD", "")
clonedframe.TextFrame.TextLabel.Text = movename
clonedframe.Visible = true
clonedframe.Position = UDim2.new(0,0,offset,0)
offset += .15
clonedframe.idk:SetAttribute("Color", clonedframe.idk.BackgroundColor3)
player.Character:GetAttributeChangedSignal(name):Connect(function() -- checking if the timer changed
if not (tick() - player.Character:GetAttribute(name) > player.Character:GetAttribute(name .. "2")) then --if cooldown is started change the color
clonedframe.idk.BackgroundColor3 = Color3.fromRGB(255,0,0)
clonedframe.idk:SetAttribute("Color", clonedframe.idk.BackgroundColor3)
while not (tick() - player.Character:GetAttribute(name) > player.Character:GetAttribute(name .. "2")) do --while cooldown is not done the size increases, but this doesn't work
clonedframe.idk.Size = UDim2.new((tick() - player.Character:GetAttribute(name)) / player.Character:GetAttribute(name .. "2"), 0, 1, 0)
task.wait()
end
clonedframe.idk.BackgroundColor3 = Color3.fromRGB(0,255,0)
clonedframe.idk:SetAttribute("Color", clonedframe.idk.BackgroundColor3)
end
end)
player.Character:GetAttributeChangedSignal("Stunned"):Connect(function() --this is just to make all the frames grey if we're stunned
if player.Character:GetAttribute("Stunned") then
clonedframe.idk.BackgroundColor3 = Color3.fromRGB(100,100,100)
else
clonedframe.idk.BackgroundColor3 = clonedframe.idk:GetAttribute("Color")
end
end)
end
end
end)
It’s a local script inside the gui in StarterGui.
The while part doesn’t seem to work, i tested it with a print but it’s only broken in game.
The game is published.
Sorry if the script is confusing, I’m a begginer so please help me improve my script if there are any other issues.
Also don’t mind anything going on in the background or the animations.