Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me, how do i do this running script work?

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

2 comments

0

LocalPlayer returns nil when called from the server.

0

Change the script to a LocalScript. It does not change any non-local things in-game, so it will not be annihilated by FE. Let me write an answer:

2 answers

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.

3 comments

0

It doesnt Work... :( i put it in a local script in the starter pack too! if you try it on a server it wont work...

0

What are the errors?

0

Players.Tommytherox.Backpack.Run:1:attempt to index field 'Character' (a nil value) :(

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)

1 comment

0

thats not what i want :\

This discussion is preserved as it was. New answers, comments, and votes are closed.