So I'm trying to make a Magic script where when you press E it would make a Fireball/Create a forcefield but I want it to be used when limited so when a player presses the key once/twice, the bar would go down until it reaches lower than the required power for the magic, so it can delay that key or some sort while it refills until it's available. But it doesn't work very well for some reason.
local UIS = game:GetService('UserInputService') local Bar = script.Parent:WaitForChild('Background'):WaitForChild('Bar') local player = game.Players.LocalPlayer local power = 10 local debounce = false repeat wait() until game.Players.LocalPlayer.Character local character = player.Character ----------------------------------------------------------------- UIS.InputBegan:connect(function(key, gameProcessed) if key.KeyCode == Enum.KeyCode.E and gameProcessed == false then debounce = true while power > 0 and debounce do power = power - 0.5 Bar:TweenSize(UDim2.new(1, 0, power / 10, 0), 'Out', 'Quint', .1, true) wait() if power <= 0 then delay(5,key) end end end end) UIS.InputEnded:connect(function(key, gameProcessed) if key.KeyCode == Enum.KeyCode.E and gameProcessed == false then debounce = false while power < 10 and not debounce do power = power + .025 Bar:TweenSize(UDim2.new(1, 0, power / 10, 0), 'Out', 'Quint', .1, true) wait() if power <= 0 then delay(5,key) end end end end)
You should try using tick()
this is a roblox function that returns how many seconds its been since 1970.
For example
local lastTick if tick()-lastTick >= 5 or lastTick == nil then print("tada") lastTick = tick() end