I have a localscript in StarterPlayerScripts and it works perfectly. The only thing i want it added is a button that only mobile players can see and when they hold it they sprint. How could i do this? This is my current code:
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local camera = workspace.Camera
local WalkSpeed = 16
local SprintSpeed = 25
local WalkFOV = 70
local SprintFOV = 90
local Tinfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local sprintgoal = {
FieldOfView = SprintFOV
}
local walkgoal = {
FieldOfView = WalkFOV
}
local sprinttween = TweenService:Create(camera, Tinfo, sprintgoal)
local walktween = TweenService:Create(camera, Tinfo, walkgoal)
UserInputService.InputBegan:Connect(function(input, gameProccessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
sprinttween:Play()
player.Character.Humanoid.WalkSpeed = SprintSpeed
end
end)
UserInputService.InputEnded:Connect(function(input, gameProccessedEvent)
if input.KeyCode == Enum.KeyCode.LeftShift then
walktween:Play()
player.Character.Humanoid.WalkSpeed = WalkSpeed
end
end)
local function endSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = walkSpeed
end
end
end
end
There was some code I found a while ago, im not sure where from / who it is by, but here it is:
local function getplatform()
if (GuiService:IsTenFootInterface()) then
return "Console"
elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then
--touchscreen computers now have touchenabled so make sure to check for lack of mouse too
--also, not all phones/tablets have accelerometer and/or gyroscope
local DeviceSize = workspace.CurrentCamera.ViewportSize;
if ( DeviceSize.Y > 600 ) then
return "Mobile (tablet)"
else
return "Mobile (phone)"
end
else
return "Desktop"
end
end
local Platform = getplatform()
print(Platform)
(in a local script)
If you want it to be regardless of what type of mobile it is, then this script would work:
local function getplatform()
if (GuiService:IsTenFootInterface()) then
return "Console"
elseif (UserInputService.TouchEnabled and not UserInputService.MouseEnabled) then
--touchscreen computers now have touchenabled so make sure to check for lack of mouse too
--also, not all phones/tablets have accelerometer and/or gyroscope
return "Mobile"
end
else
return "Desktop"
end
end
local Platform = getplatform()
if Platform == "Mobile" then
--Button visibility and control script goes here
end