✓ Accepted answer
An inputObject includes a changed event. You could use this to detect when the key is released or you could use the InputEnded and use a boolean to check its state.
Using the changed event
function onSprintKeyPress(inputObject, gameProcessed)
if SprintSettings.CanSprint and not SprintSettings.IsSprinting and inputObject.KeyCode == SprintSettings.Key then
Sprint()
inputObject.Changed:Wait()
end
end
UIS.InputBegan:Connect(onSprintKeyPress)
Using the InputEnded event
local function onSprintKeyPress(inputObject, gameProcessed)
if SprintSettings.CanSprint and not SprintSettings.IsSprinting and inputObject.KeyCode == SprintSettings.Key then
Sprint()
end
end
UIS.InputBegan:connect(onSprintKeyPress)
local function onSprintRelease(inputObject, gameProcessed)
if inputObject.KeyCode == SprintSettings.Key and SprintSettings.IsSprinting then
end
end
UIS.InputEnded:Connect(onSprintRelease)
I hope this helps. Please comment if you do not understand how / why this code works.
1 comment
;