Hello, fellow helpers! I have a problem... I made a Shift to Run script but it doesn't seem to be working even though it looks fine to me. I've tried to put it in a StarterGUI too, but it doesn't work either.
Here's the LocalScript:
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:wait() local char = plr.Character or plr.Character.CharacterAdded:wait() local humanoid = char.Humanoid local RunR6 = script.Parent["Run (R6)"] local RunR15 = script.Parent["Run (R15)"] local PlayRunR6 = humanoid:LoadCharacter(RunR6) local PlayRunR15 = humanoid:LoadCharacter(RunR15) local UserInputService = game:GetService('UserInputService') UserInputService.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if Enum.HumanoidRigType.R6 then humanoid.WalkSpeed = 24 PlayRunR6:Play() elseif Enum.HumanoidRigType.R15 then humanoid.WalkSpeed = 24 PlayRunR15:Play() end end end)
This checks if you have pressed the Shift key on the left side of keyboard. If it is pressed, it triggers another if statement about detecting what RigType you're avatar is to determine what animation needs to be played (I made an R6 and R15 version of a running animation). When it sees this, it changes the humanoid's (player's) walkspeed to 24 and it plays the animation.
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") local RunR6 = script.Parent["Run (R6)"] local RunR15 = script.Parent["Run (R15)"] local PlayRunR6 = humanoid:LoadAnimation(RunR6) -- Notice local PlayRunR15 = humanoid:LoadAnimation(RunR15) -- Notice local UserInputService = game:GetService('UserInputService') UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if humanoid.RigType == Enum.HumanoidRigType.R6 then humanoid.WalkSpeed = 24 PlayRunR6:Play() elseif humanoid.RigType == Enum.HumanoidRigType.R15 then humanoid.WalkSpeed = 24 PlayRunR15:Play() end end end)
In the lines where I wrote the last two "Notice" comments I made in your script, you forgot to write "humanoid.RigType ==" before your "Enum.HumanoidRigType".
Also on the first "Notice", you write the .CharacterAdded event next to your player itself (plr in your script), not next to its Character.
Finally I added a WaitForChild() in the next "Notice" line, its a good practice to use the WaitForChild() function on instances you are not sure have loaded yet (the player's humanoid in this case) since your script will often break otherwise.
Hope this answers your question, best of lucks!
EDIT:
Didn't see that on line 6 and 7 you used the :LoadCharacter() function when you should use :LoadAnimation(). Hopefully the script will work now.
You could also just use this... Put this in a LocalScript inside of StarterCharacterScripts
-- Locals local Mouse = game.Players.LocalPlayer:GetMouse() local char = game.Players.LocalPlayer.Character local sb = string.byte -- Main Mouse.KeyDown:Connect(function(keybyte) Key = string.lower(keybyte) if sb(keybyte) == 48 then char.Humanoid.WalkSpeed = 21 end Mouse.KeyUp:Connect(function(keybyte) if sb(keybyte) == 48 then char.Humanoid.WalkSpeed = 16 end end) end)
Try this, if you still have a problem occurring, I'll properly debug it.
Make sure this is in a LocalScript in StarterPack or StarterGui.
local plr = game.Players.LocalPlayer local char = plr.Character local humanoid = char:WaitForChild("Humanoid") local RunR6 = script.Parent["Run (R6)"] local RunR15 = script.Parent["Run (R15)"] local PlayRunR6 = humanoid:LoadAnimation(RunR6) -- Notice local PlayRunR15 = humanoid:LoadAnimation(RunR15) -- Notice local UserInputService = game:GetService('UserInputService') UserInputService.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if humanoid.RigType == Enum.HumanoidRigType.R6 then humanoid.WalkSpeed = 24 PlayRunR6:Play() elseif humanoid.RigType == Enum.HumanoidRigType.R15 then humanoid.WalkSpeed = 24 PlayRunR15:Play() end end end) UserInputService.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then if humanoid.RigType == Enum.HumanoidRigType.R6 then humanoid.WalkSpeed = 16 PlayRunR6:Play() elseif humanoid.RigType == Enum.HumanoidRigType.R15 then humanoid.WalkSpeed = 16 PlayRunR15:Play() end end end)