Attempt to index nil with 'Move'

so I’m making game and I want player move right if he press q don’t ask me why

this is the script

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local humanoid = player.Character:FindFirstChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(keyCode)

if keyCode.keyCode == Enum.KeyCode.Q then

humanoid:Move(Vector3.new(1, 0, 0), true)

end

end)

and I got this on output

attempt to index nil with ‘Move’

do humanoid:MoveTo() it should work then

You are trying to get the humanoid of a character before it has loaded. Try this:

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
  1. Replace the FindFirstChild with WaitForChild (as the humanoid hasn’t loaded in yet)

it says attempt to index nil with ‘Move’, that means that move does not exsist, but the Humanoid does.

that what i got on output Unable to cast value to Object

Actually, humanoid:Move is an actual function of humanoid.

1 Like

Unable to cast value to Object that what i got on output

This is the improved script:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local usi = game:GetService("UserInputService")
usi.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q then
        humanoid:Move(Vector3.new(1, 0, 0), true)
    end
end)

This should now work properly @MONSTERGAMES3609

still do not worked idk whyyyy

Can you please show the error if there was one?
Also, add a print statement after the input line so you can see whether input is registering.

there is no errors but I change= to ==

OOPS, sorry, yes there should be == not =.

Also check your humanoid:Move system here:
https://developer.roblox.com/en-us/api-reference/function/Humanoid/Move

the script work but noting happen

here u go

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local Character = game.Players.LocalPlayer.CharacterAdded:Wait()

local humanoid = Character:WaitForChild("Humanoid")

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:connect(function(keyCode)
local HRP = Character:FindFirstChild("HumanoidRootPart")

	if keyCode.keyCode == Enum.KeyCode.Q then

		humanoid:MoveTo(HRP.Position + Vector3.new(1,0,0))

	end

end)

Edit: you can change the 1,0,0 to be a bigger number lol

do not work there is noting on output too

Can you send me the script? Because it works for me.

wait wait where you put the script + its local script or normal

put the script in a local script, and make the local script’s parent starterplayer > starterplayerscripts
or u can put it in starter gui, and it should work.