This is all in a localscript within a tool. I want the localscript to run a number that goes up from 0 to 100 as the player holds down the letter E. If the player lets go in between, the number stops where it’s at. Simple power level system. Everything works perfectly EXCEPT for the part where the number ends when the player lets go of the key. This is due to the script never detecting when :IsKeyDown() is no longer true. How many I fix this? Script provided below.
local function onPowerScroll(button, track, event) -- event is the main RemoteEvent
local PwrChangeRE = event.PowerChangeRE
local PwrHeldRE = event.PowerHeldRE
local PwrReleaseRE = event.PowerReleaseRE
local powerDone = false
PwrHeldRE:FireServer()
for power = 0, 100, 1 do
if power < 100 then
if button then -- button being UserInputService:IsKeyDown(Enum.Keycode.E)
print("it aint over bro")
elseif not button then
print("its over! send to server!")
PwrReleaseRE:FireServer()
onAction(track, event) -- no need for the context to this function
break
end
elseif power == 100 then
print("power is 100! tell the server!")
PwrReleaseRE:FireServer()
onAction(track, event) -- no need for the context to this function
break
end
task.wait(0.00001)
end
end