You can use
NewButton.Price = ItemData:FindFirstChild("Price)
end)
end
You can use
NewButton.Price = ItemData:FindFirstChild("Price)
end)
end
You could use Viewport frame if you want to render the actual model , or use ImageLabels if you want to upload photos
I tried doing this just now and I got no errors in the output but now nothing still shows in the shop ui
This is what I mean by item image (This is an older screenshot from when the items would show)
My fault.
Instead of
NewButton.Price
do
NewButton.Price.Text
Also for Image just do this in your itemData:
["Apple"] = {
["Price"] = 35,
["Item"] = ShopItemsFolder:WaitForChild("Apple"),
["Image"] = "string" -- Replace string with your image asset-id, you can get this, by inserting a decal into workspace, paste the link of your image into the decal, the decal transforms the link automatically into a asset-id. Then you just copy that asset-id and replaces string with that.
},
I have another error again, this time it is
Unable to assign property Text. string expected, got nil
Not sure if something is wrong with the code as a whole but this is what it is right now
local ItemsDataMS = require(game:GetService("ReplicatedStorage"):WaitForChild("ItemsModule"))
local ButtonTemplate = script.Item
local Remote = game:GetService("ReplicatedStorage")
for ItemName, ItemData in pairs(ItemsDataMS) do
local NewButton = ButtonTemplate:Clone()
NewButton.ItemName.Text = ItemName
NewButton.Price.Text = ItemData["Price"]
NewButton.Image = ItemData["Image"]
local ButtonDebounce = false
NewButton.Activated:Connect(function()
if ButtonDebounce then return end
ButtonDebounce = true
Remote:FireServer(ItemName)
task.wait(1)
ButtonDebounce = false
end)
end
and also if I could ask for help with another small thing, how would I add a dollar sign in behind the price on the text label using a string because it gives me a different error when I do this
NewButton.Price.Text = "$".. ItemData["Price"]
Hi,
Please show me your updated Data Dictionary, and also show me which line the error is on.
Here the Data Directionary is
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ShopItemsFolder = ReplicatedStorage:WaitForChild("ShopItems")
local module = {}
module.ItemsData = {
["Apple"] = {
["Price"] = 35,
["Item"] = ShopItemsFolder:WaitForChild("Apple"),
["Image"] = 4784482033,
},
["Sandwich"] = {
["Price"] = 25,
["Item"] = ShopItemsFolder:WaitForChild("Sandwich"),
["Image"] = 4784482033,
},
["Pizza"] = {
["Price"] = 20,
["Item"] = ShopItemsFolder:WaitForChild("Pizza"),
["Image"] = 4784482033,
},
["Bloxy-Cola"] = {
["Price"] = 15,
["Item"] = ShopItemsFolder:WaitForChild("Bloxy-Cola"),
["Image"] = 4784482033,
},
}
return module
This is the error line (In the ClientSide script)
NewButton.Price.Text = ItemData["Price"]
Hi, you should paste the whole string you got from the decal “Texture”, and keep it like a string. Should look something like this:
"rbxassetid://6126528987"
What is the different error, when you do this?
NewButton.Price.Text = "$".. ItemData["Price"]
I get this error
Players.def.PlayerGui.Shop.Frame.Template1.LocalScript:9: attempt to concatenate string with nil
Try print ItemData, because it tells you that “Price” couldn’t be found in the ItemData, since you try to combine string (the dollar sign) with nil (which tells us that ItemData[“Price”] is not present)
Edit: also know why.
Instead of:
for ItemName, ItemData in pairs(ItemsDataMS) do
do
for ItemName, ItemData in pairs(ItemsDataMS.ItemsData) do -- Since it's the "ItemsData" dictionary inside our ItemsData ModuleScript, that we want to loop through, and not the ModuleScript itself.
I printed the ItemData and this is what I got after doing what you also said to edit
It seems to show the correct ItemData but nothing shows up in the shop
Here is what was printed
Make sure to set the NewButton.Parent to the frame, at the very end of the loop
It works now!
--Serverscript
local Remote = game.ReplicatedStorage.PurchaseItem
local ItemsDataMS = require(game.ReplicatedStorage.ItemsModule)
Remote.OnServerEvent:Connect(function(Player, ItemType)
if not ItemType then return end
local ValidItemType = tostring(ItemType)
if not ValidItemType then return end
if not ItemsDataMS[ValidItemType] then return end
print("Client picked "..ValidItemType.." the cost of it is "..ItemsDataMS[ValidItemType]["Price"])
-- In other words "ItemsDataMS[ValidItemType]["Price"]" (if apple, means) ItemsDataMS["Apple"]["Price"], which gives the price of 35 in this case
end)
Make sure to fix the error on the server also. Should be ItemsDataMS.ItemsData, not ItemsDataMS
Alright now I get an output error which is this
ServerScriptService.ShopPurchase:10: attempt to index nil with 'Price'
Do it both places, check the next line on the server aswell
Alright it works now!
Now I think I still just have one last question and I should be fine from here on out, but how do I grab the points from the leaderstats and substract the player’s stats from the price of the item