local UIS = game:GetService("UserInputService")
local char
local players = game.Players
UIS.InputBegan:Connect(function(input, plr)
if input.KeyCode == Enum.KeyCode.LeftShift then
plr.Character:FindFirstChild("Humanoid").WalkSpeed = 20
end
end)
To be clear, this is a LocalScript located in StarterPlayerScripts.
The output gives me an error, saying “Players.pevdn.PlayerScripts.LocalScript:9: attempt to index boolean with ‘Character’”
Any thoughts?
Since this is the client, you can use Players.LocalPlayer to get the player. And also, InputBegan’s second parameter is gameProcessedEvent not plr.
local UIS = game:GetService("UserInputService")
local char
local players = game.Players
local plr = players.LocalPlayer
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
plr.Character:FindFirstChild("Humanoid").WalkSpeed = 20
end
end)
First, the script should be in StarterCharacterScripts
Second, you should get the character from the localPlayer
local players = game.Players
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character:FindFirstChild("Humanoid").WalkSpeed = 20
end
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character:FindFirstChild("Humanoid").WalkSpeed = 16
end
end)