im making a sprint script, but i have no idea whats causing it to not sprint. can anyone help me pls?
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local InputServ = game:GetService("UserInputService")
local DB = false
InputServ:IsKeyDown(function(Input)
if Input == Enum.KeyCode.LeftShift then
Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 20
DB = true
while DB == true do
if Input ~= Enum.KeyCode.LeftShift then
DB = false
break
else
task.wait(0.001)
end
end
repeat wait() until DB == false
Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 16
end
end)
You’re not updating local Character and also you could do this instead of while true do (this could lead to probably memory leak and if Input ~= Enum.KeyCode.LeftShift wrong input being used could stop this sprint)
I’m sure you’re trying your best to do this but still you need knowledge
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local InputServ = game:GetService("UserInputService")
local DB = false
InputServ.InputBegan:Connect(function(Input:InputObject,gpe:boolean)
if Input.KeyCode == Enum.KeyCode.LeftShift then
Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 20
DB = true
end
end)
InputServ.InputEnded:Connect(function(Input:InputObject,gpe:boolean)
if Input.KeyCode == Enum.KeyCode.LeftShift then
DB = false
Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 16
end
end)