Simulator backpack checking script not working

Got a script in a coin for a simulator that’s supposed to check what custom backpack from a module script a player has when it’s touched

Coin’s Script:

local RS = game:GetService("ReplicatedStorage")
local Backpacks = require(RS.BPacks.Packs) -- Get list of Backpacks

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local PlayerBPack = player.BPacks.Value -- Get player's custom backpack (StringValue)
		local CheckPack = table.find(Backpacks.Packs,PlayerBPack) -- Look for PlayerBPack in the Module script
		print(CheckPack) -- Print Player's current BPack + Info	
	end
end) 

Module Script:

Module = {}
Module.Packs = {
	Default = {
		Name = "Default",
		Size = 5,
		Cost = 0
		},
}
return Module

CheckPack keeps printing nil and I’m not sure why, can someone help me?

You’re using a dictionary, so table.find wont work I believe. If the contents of the BPacks value is the name of the backpack, such as “Default”, you can try this

local CheckPack = Backpack.Packs[PlayerBPack]

So it will try to find the right key from it and if it doesn’t, then it will return nil

Edit: Also is that module script only for storing the backpacks? You can put that inside of Module = {} and change some of the code around if it’s only used for one purpose

1 Like