I’m very new to scripting and I don’t know how to make sense of the information I’ve found so far. I’ve already implemented a simple local shift to run script for PC users, so I’m mainly trying to make it fair for those on mobile devices.
✓ ANSWER ACCEPTED
How do I create a button to sprint for mobile/tablet users?
2 answers
✓ Accepted answer
Hey nymphct :)
To do this, you can use MouseButton1Down
So you'd be using a LocalScript, with the following code.
local sprinting = false -- Variable to detect whether to walk, or to sprint.
script.Parent.MouseButton1Down:Connect(function() -- Assuming the Button is above the script
if sprinting == false then
workspace[game.Players.LocalPlayer.Name].Humanoid.WalkSpeed = 27
sprinting = true
else
workspace[game.Players.LocalPlayer.Name].Humanoid.WalkSpeed = 16
sprinting = false
end
end)
Please remember to mark as Correct, or Upvote if you you're satisfied with the answer I provided.
You can also do something like this so that your button only appears to touchscreen players
if Check() == true then
local Mobile = game:GetService("UserInputService").TouchEnabled
if Mobile then
Player.PlayerGui.Mobile_Gui.Enabled = true
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
