Getting wrong values from module script

  1. What do you want to achieve? Keep it simple and clear!

I want to clone buttons into an shop ui, And then change the text elements to values from table (Weapon shop)

  1. What is the issue?

The prices of the tools are different from the module

Module Script

local Weapons = {
	[1] = {
		["Name"] = "Bat",
		["Description"] = "Dangerous.",
		["Price"] = 0,
	},

	[2] = {
		["Name"] = "Knife",
		["Description"] = "Pointy weapon, good for stabbing.",
		["Price"] = 100,
	},
	
	[3] = {
		["Name"] = "Duck",
		["Description"] = "Quack! Quack! Quack!",
		["Price"] = 125,
	}
}

return Weapons

Local Script (Shop UI)

local ShopItems = require(game.ReplicatedStorage.ShopItems)
local WeaponFrame = game.ReplicatedStorage.WeaponFrame

local Player = game.Players.LocalPlayer

for weapon, value in pairs(ShopItems) do
	
	local WeaponFrameClone = WeaponFrame:Clone()
	WeaponFrameClone.NameTxt.Text = value.Name
	WeaponFrame.CostTxt.Text = value.Price .. "💰"

	WeaponFrameClone.Parent = script.Parent
	
end

1 Like
for weapon, value in pairs(ShopItems) do
	
	local WeaponFrameClone = WeaponFrame:Clone()
	WeaponFrameClone.NameTxt.Text = value["Name"]
	WeaponFrame.CostTxt.Text = value["Price"].. "💰"

	WeaponFrameClone.Parent = script.Parent
	
end

Table expected got nil, what do i do?

oops this should work.

for weapon, value in pairs(ShopItems) do
	
	local WeaponFrameClone = WeaponFrame:Clone()
	WeaponFrameClone.NameTxt.Text = value["Name"]
	WeaponFrame.CostTxt.Text = value["Price"].. "💰"

	WeaponFrameClone.Parent = script.Parent
	
end

Hmm thats weird it still shows 0,0,100 for the prices instead of 0,100,125

It seems you are in teamcreate:
image

Are you sure you clicked “Apply edits”?

I did and it’s still not working, i dont really know why

why do you have return Weapons in the localscript?

Oh, thats a module script . . .

in your code its in the localscript.

try adding prints print(value.Name, value.Price)

Oh, thats actually not in my local script i just put it in the post by a mistake

printing the values works fine, but i dont know what to do with the text

1 Like

Thx so much for trying to help me, im a dumbass and didnt notice i was changing a completely different variable for the pricetext

1 Like