What do you want to achieve? I want to get a cloaker ability from pd2
What is the issue? I want it to stop running after you click / 4.5 seconds passed. But whenever I click too fast, the next time I activate the ability, the 4.5 second timer blocks it off.
What solutions have you tried so far? I tried using some confusing shenanigans but those didn’t work so now I’m here.
if input.KeyCode == Enum.KeyCode.Q and not isCharging and canPlay then
canShoot = false
canSwitch = false
canReload = false
isCharging = true
chargeEvent:FireServer(true)
for i,v in pairs(framework.vm:GetDescendants()) do
if v:IsA("BasePart") then
v:SetAttribute("OldTransparency", v.Transparency)
v.Transparency = 0.999999
end
end
autoRunning = run.RenderStepped:Connect(function(dt)
hum:Move(Vector3.new(0,0,-1), true)
end)
task.wait(4.5)
if isCharging then
isCharging = false
autoRun = false
canShoot = true
canSwitch = true
canReload = true
autoRunning:Disconnect()
chargeEvent:FireServer(false)
end
end
To add on to what @Earthraphobic2 said, make a debounce, but make sure it is defined outside of the function. you defined the canShoot, canSwitch, canReload, and isCharging inside the input and that will break your code since every time the key is pressed it will reload those variables, make sure to define it outside before the input code.
I think this is what you need to do (from what I understood), let me know if this is what you need.
local debounce = false
if input.KeyCode == Enum.KeyCode.Q and not isCharging and canPlay and not debounce then
print("Activating ability...") -- Debug print statement
debounce = true
canShoot = false
canSwitch = false
canReload = false
isCharging = true
chargeEvent:FireServer(true)
for i,v in pairs(framework.vm:GetDescendants()) do
if v:IsA("BasePart") then
v:SetAttribute("OldTransparency", v.Transparency)
v.Transparency = 0.999999
end
end
autoRunning = run.RenderStepped:Connect(function(dt)
hum:Move(Vector3.new(0,0,-1), true)
end)
print("Waiting for 4.5 seconds...") -- Debug print statement
wait(4.5)
if isCharging then
print("Deactivating ability...") -- Debug print statement
isCharging = false
autoRun = false
canShoot = true
canSwitch = true
canReload = true
autoRunning:Disconnect()
chargeEvent:FireServer(false)
end
debounce = false
end
I’m sorry if I didn’t explain correctly, but that’s not really the thing I strive for. I want the lines after the task.wait(4.5) to not interrupt the next time I use the ability