Player turns nil after ModuleScript fires to another ModuleScript

So I’m currently making a trail system but Player object turns nil after ModuleScript fires to another ModuleScript, I used printing to identify that it is nil and tried to search the error on google but it’s not the same problem.

Any info can help!

ModuleScript1 - The first modulescript where it functions when the player buys the trail(player obj not nil yet

function TrailModule.BuyTrail(LocalPlayer, Trail)
	local TrailFolder = LocalPlayer:WaitForChild("Trails")
	
	local Bits = LocalPlayer:WaitForChild("leaderstats").Bits
	local Price = Trail:WaitForChild("Price")
	
	if Price.Value <=  Bits.Value then
		
		Bits.Value -= Price.Value
		local PurchasedTrail = Trail:Clone()
		PurchasedTrail.Parent = TrailFolder
		PlayerDataModule.TrailSave(LocalPlayer)
		print(LocalPlayer)
		print("Puchased a Trail!")
		
	end
end

ModuleScript2

function PlayerDataModule:TrailSave(LocalPlayer)
	--local TrailStore = DataStore2Module("Trails", LocalPlayer)
	print(LocalPlayer)
	
	local OwnedTrails = {}
	
	for _, trl in pairs(LocalPlayer.Trails:GetChildren()) do
		table.insert(OwnedTrails, trl.Name)
		print(trl.Name)
	end
	
	local success, err = pcall(function()
		--TrailStore:Set(OwnedTrails)
		--TrailStore:Save()
	end)
	end

It’s because in your first module, you are calling the function with a period instead of a colon.

You should instead do

PlayerDataModule.TrailSave(PlayerDataModule, LocalPlayer)

or

PlayerDataModule:TrailSave(LocalPlayer)

Those two are the exact same thing, the first passes self manually whereas the second one has it passed automatically.

1 Like