I’m making a shift-to-sprint script, and it does nothing.
Script:
local player = game.Players.LocalPlayer
local mouse = player.GetMouse()
local sprintspeed = 40
mouse.KeyDown(function(key)
if key == "0" then
player.Character.Humanoid.WalkSpeed = sprintspeed
end
end)
mouse.KeyUp:Connect(function(key)
if key == "0" then
player.Character.Humanoid.WalkSpeed = 16
end
end)
Why would you want to be the key “0” numkey to be the sprint button, i think you should change it to left shift or any shift buttons so it’s more easier.
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
local Character = game.Players.LocalPlayer.Character
if Character ~= nil then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid ~= nil then
Humanoid.WalkSpeed = 40
end
end
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
local Character = game.Players.LocalPlayer.Character
if Character ~= nil then
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid ~= nil then
Humanoid.WalkSpeed = 16
end
end
end
end)
-- [[Service Calling]] --
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
-- [[Player Content]] --
local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() or workspace:FindFirstChild(LocalPlayer.Name)
local Humanoid = Character:WaitForChild("Humanoid")
-- [[Basics]] --
local SprintSpeed = 40 -- Sprint speed
local DefaultSpeed = 16 -- Default one
-- [[Start Of Script]] --
UserInputService.InputBegan:Connect(function(Init,Deny)
if UserInputService.KeyboardEnabled and not Deny and Init.KeyCode == Enum.KeyCode.LeftShift or Init.KeyCode == Enum.KeyCode.RightShift then
if Humanoid then
Humanoid.WalkSpeed = SprintSpeed
end
end
end)
UserInputService.InputEnded:Connect(function(Init,Deny)
if UserInputService.KeyboardEnabled and not Deny and Init.KeyCode == Enum.KeyCode.LeftShift or Init.KeyCode == Enum.KeyCode.RightShift then
if Humanoid then
Humanoid.WalkSpeed = DefaultSpeed
end
end
end)