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

Output reads: attempt to index function with 'Play' what is the problem?

Asked by
Jo1nts 134
3 years ago
Edited 3 years ago

I'm trying to make an animation play as shown in the function however, the outputs always prints out an error: attempt to index function with 'Play' which is the :Play() part I don't seem to know what is causing the error and how to fix it.

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local animationid = game.ReplicatedStorage.Animation
local animation = humanoid:LoadAnimation(animationid)

    local function animation()
        animation:Play() -- ERROR LINE
    end

1 answer

Log in to vote
1
Answered by 3 years ago

You override the "animation" variable by creating a function with the same name.

local a = 1
print(type(a)) --> number

local function a() 
end

print(type(a)) --> now it's a function!

Rename animation() to something else, and you also need to call the function afterwards or it won't do anything

Ad

Answer this question