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

"attempt to call a userdata value"?

Asked by 4 years ago
Edited 4 years ago

What we've got here is a small local-script located in StarterCharacterScripts that (I don't know if giving a breakdown of it is redundant, I'm new to this website) listens to player input concerning the keycode "S", which is my choice for if the player moves backwards.

The error is whenever I run the game and try moving my character backwards with the "S" key, the following message appears in the output each input. The error source is this local script, on line 5.

22:00:04.265 - attempt to call a userdata value

Here is the code:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local backwards_anim = ReplicatedStorage:WaitForChild("backwards_anim")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

local function inputbegan(inputObject, gameProcessedEvent)

    if gameProcessedEvent then return end

        if inputObject.UserInputType == Enum.UserInputType.Keyboard then
            local KeyCode = inputObject.KeyCode

            if KeyCode == Enum.KeyCode.S then
                humanoid:GetState(state)

                if state == Enum.HumanoidStateType.Running or Enum.HumanoidStateType.RunningNoPhysics then
                    backwards_anim:FireServer(humanoid)
                    print("Animation request!")

            end
        end
    end
end



UserInputService.InputBegan:Connect(inputbegan)

Any help would be greatly appreciated!

1
Which line is the error on? oilkas 364 — 4y
1
Try getting Humanoid in line 4 like this: local humanoid = script.Parent:WaitForChild("Humanoid") because the script is in startercharacterscripts and see if that helps?? oilkas 364 — 4y
0
Will try that when I get back onto my computer later (currently on mobile). DemonHunterz6 35 — 4y
0
Sorry, didn't work. The same error still showed up. DemonHunterz6 35 — 4y

Answer this question