Hi,
Im trying to code my mobile button to work so that when pressed, it interracts with my stamina function and when released, the player stops sprinting and the stamina regenerates. This is the code so far:
if userInputService.TouchEnabled then
script.Parent.Sprint.Visible = true
script.Parent.Sprint.MouseButton1Click:Connect(function()
if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 and IsAllowed then
character.Humanoid.WalkSpeed = sprintSpeed
end
end)
script.Parent.Sprint.MouseButton1Click:Connect(function()
character.Humanoid.WalkSpeed = walkSpeed
end)
end
As is the stamina doesnt seem to disable (once you click the button the player runs until the bars out) however ive included the second part to include the relevant code needed to get the player to walk again (and hence recharge the bar)
I know one way would be to possibly use InputBegan and InputEnded however I am not sure how to adapt them for use in the context of an on screen button.
Thanks