Can you help me please? i inserted it into the starter pack on a serverside script with a animation inside of it
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "50" local playr = game.Players.LocalPlayer local mouse = playr:GetMouse() local animation = script:WaitForChild("Animation") function run(key) if key == "q" then local animationTrack = playr.Character.Humanoid:LoadAnimation(animation) animationTrack:Play() script.Fwoosh:Play() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "250" end end game.Players.LocalPlayer:GetMouse().KeyDown:connect(run) function dont(key) if key == "q" then game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "50" --how fast you will walk end end game.Players.LocalPlayer:GetMouse().KeyUp:connect(dont) wait(1) local animationTrack = playr.Character.Humanoid:LoadAnimation(animation) animationTrack:Pause() pls help
1.
Change the script to a LocalScript
. LocalPlayer cannot be indexed by the server, so it needs to be local, or else it will error.
Plus, this script doesn't change anything in the server, so it being a LocalScript
is just better in general.
2.
KeyDown
is deprecated, so you should UserInputService
instead.
Let me convert it for you:
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "50" local playr = game.Players.LocalPlayer local mouse = playr:GetMouse() local animation = script:WaitForChild("Animation") local uis = game:GetService("UserInputService") local animationTrack = playr.Character.Humanoid:LoadAnimation(animation) function run(key,gp) if key.KeyCode == Enum.KeyCode.Q and gp == false then -- so it doesn't run when typing in chat etc. animationTrack:Play() script.Fwoosh:Play() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "250" end end uis.InputBegan:connect(run) function dont(key) if key.KeyCode == Enum.KeyCode.Q and gp == false then animationTrack:Stop() game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = "50" --how fast you will walk end end uis.InputEnded:connect(dont) wait() local animationTrack = playr.Character.Humanoid:LoadAnimation(animation)
Your code should be fixed. If you're having trouble with UserInputService
, try going to the wiki page for help. I don't have access to it right now, so I can't link you.
Hope I helped!
~TDP
TIP
Try using Tab to format your code, not Space as it is very inconsistent.
Hello, There's a GUI I made for this. Go to StarterGui, insert a ScreenGUI, Put a textbutton that says : "Run" And insert this script into the TextButton.
function onClick(mouse) script.Parent.Parent.Parent.Parent.Character.Humanoid.WalkSpeed = [WALKSPEED HERE]
end script.Parent.MouseButton1Click:connect(onClick)