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

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

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

✓ Accepted answer

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

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