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

Run script help? (bump)

Asked by 8 years ago

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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

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 tommytherox 5 — 8y
0
Its friends only though, friend me for a short time period thanks for your help :) tommytherox 5 — 8y
Ad

Answer this question