Function not working | OOP

function methods:GiveTools()
	print('Hi.')
	local xd = Ranks[self.PDrank]

	for i,v in pairs(xd.Tools) do
		print(v.Name,i)
			v:Clone().Parent = self.Player.Backpack
		end
	
end

That’s my code.
It doesn’t even prints hi.
No clue why.

local Ranks = {
	{Name='Cadet', Tools = {game.ReplicatedStorage.Tools["X-26"]}},
}

^ Ranks Table

methods.__index = methods

methods.StartCharacter = function(Player)
	(ignore this, here i create metatable and more)
end



function methods:GiveTools()
	print('Hi.')
	local xd = Ranks[self.PDrank]

	for i,v in pairs(xd.Tools) do
		print(v.Name,i)
			v:Clone().Parent = self.Player.Backpack
		end
	
end

Find the solution, sorry
:slightly_frowning_face:

Firstly, your code is missing an end. Replace your function with this code:

function methods:GiveTools()
	print('Hi.')
	local xd = Ranks[self.PDrank]

	for i,v in pairs(xd.Tools) do
		print(v.Name,i)
			v:Clone().Parent = self.Player.Backpack
		end
	end -- 'end' here to end the for loop
end

And a function doesn’t just run when you define it. You must call it, by putting this in your script after the function:

methods:GiveTools()
2 Likes

You never return the meta table :roll_eyes:

This post lacks details. Add context