Self is somehow nil (it isnt)

bro so at function animations:stopAnimation() when i do self.currentAnimation:Stop() it says attempt to index nil with Stop when you can clearly see its not nil in the above function because it plays after :skull:

function animations.new()
	local newAnimationHandler = setmetatable({
		currentAnimation = nil
	}, animations)
	return newAnimationHandler
end

function animations:playAnimation(animation)
	if self.currentAnimation then return end
	
	local player = game:GetService("Players").LocalPlayer
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	self.currentAnimation = humanoid:LoadAnimation(animation) --now its not nil
	self.currentAnimation:Play() -- it works
end

function animations:stopAnimation()
	self.currentAnimation:Stop() -- it says its nil?????????????????????????
	self.currentAnimation = nil
end
1 Like

You probably forgot to use a β€œ:” when calling it.

image

hm, sorry I don’t know then.

show the whole code then we can anaylyze

that is the whole code, and i fixed it

i was creating 2 new animations.new() instances, thank you though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.