Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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
0
LocalPlayer returns nil when called from the server. BlackJPI 2658 — 8y
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: TheDeadlyPanther 2460 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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.

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... tommytherox 5 — 8y
0
What are the errors? TheDeadlyPanther 2460 — 8y
0
Players.Tommytherox.Backpack.Run:1:attempt to index field 'Character' (a nil value) :( tommytherox 5 — 8y
Ad
Log in to vote
0
Answered by
Osru 0
8 years ago

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)

0
thats not what i want :\ tommytherox 5 — 8y

Answer this question