I have a sprint script that works completely fine on computers but I don't know how to make it work on Xbox. I want it to work like it does in Jailbreak, where LT is the sprint button.
local mouse = game.Players.LocalPlayer:GetMouse() local running = false function getTool() for _, kid in ipairs(script.Parent:GetChildren()) do if kid.className == "Tool" then return kid end end return nil end mouse.KeyDown:connect(function (key) -- Run function key = string.lower(key) if string.byte(key) == 48 then running = true local keyConnection = mouse.KeyUp:connect(function (key) if string.byte(key) == 48 then running = false end end) for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (70+(i*2)) wait() end game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30 repeat wait () until running == false keyConnection:disconnect() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) wait() end end end)
As an addition, can anybody tell me why when I press the 0 key it also acts as the shift key? Thanks!
As kingdom5 mentioned, getting keyboard (or any other device's) inputs from the mouse is deprecated and should not be used at all. Instead use UserInputService or ContextActionService to receive inputs from the controller, but I would prefer UIS:
local running = false local UIS = game:GetService("UserInputService") function getTool() for _, kid in ipairs(script.Parent:GetChildren()) do if kid.className == "Tool" then return kid end end return nil end UIS.InputBegan:Connect(function(inputobj, gpe) local key = inputobj.KeyCode if key == Enum.KeyCode.ButtonL2 then running = true for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (70+(i*2)) wait() end game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30 end end) UIS.InputEnded:Connect(function(inputobj, gpe) local key = inputobj.KeyCode if key == Enum.KeyCode.ButtonL2 then running = false game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 for i = 1,5 do game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) wait() end end end)
Also notice that I modified other parts of the script aswell; your scripting was inefficient