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

Run script help? (bump)

Can you help me please? i inserted it into the starter pack on a local script with a animation inside of it i also has this error: Players.Tommytherox.Backpack.Run:1:attempt to index field 'Character' (a nil value) please help :(

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)

1 answer

✓ Accepted answer

You need to wait for the player's character before manipulating its children.

local playr = game.Players.LocalPlayer
local mouse = playr:GetMouse()
local animation = script:WaitForChild("Animation")
local uis = game:GetService("UserInputService")

local character = playr.CharacterAdded:wait()
character:WaitForChild("Humanoid")
character.Humanoid.WalkSpeed = 50
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)

Hope this helped.

2 comments

0

it works on roblox studio test mode but not on a roblox server... why? i added you to team create: https://www.roblox.com/games/237860038/Velocity-Run-Closed-Alpha

0

Its friends only though, friend me for a short time period thanks for your help :)

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