Hey guys! I’m trying to make a shift to spring script and this is my code. It’s not working nor showing any errors. Also it’s in a localscript in starterCharacterScripts. Thanks.
local UserInputService = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
p.CharacterAdded:Connect(function(c)
local h = c:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(input, processed)
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and not processed then
h.WalkSpeed = 30
else
h.WalkSpeed = 10
end
end)
end)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local c = player.Character
local h = c:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(input, processed)
while true do
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
h.WalkSpeed = 30
else
h.WalkSpeed = 10
end
wait(0.01)
end
end)
There you are my good Sir, you cannot use the function of a player being added to the game. You need to do it on a UIS event. If you put the script inside of a characterAdded script, it will only run once. I hope this helps.
Don’t use this solution, it’s so intensive for no reason.
Use this instead:
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local c = player.Character or player.CharacterAdded:Wait()
local h = c:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.LeftShift then
if h then
h.WalkSpeed = 30
end
end
end)
UserInputService.InputEnded:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.LeftShift then
if h then
h.WalkSpeed = 16
end
end
end)