#Module script cant be used on both client and server
1 messages · Page 1 of 1 (latest)
Ignore the item names
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage:WaitForChild("PurchaseEvent")
local ServerStorage = game:GetService("ServerStorage")
local ItemFolder = ServerStorage:WaitForChild("Items")
local Items = {}
Items.Burger = {
["Price"] = 10,
["ItemPath"] = ItemFolder:WaitForChild("Burger")
}
Items.Bepis = {
["Price"] = 5,
["ItemPath"] = ItemFolder:WaitForChild("Bepis")
}
Items.Leader = {
["Price"] = 100,
["ItemPath"] = ItemFolder:WaitForChild("Leader")
}
function Items.Purchase(Player, Item)
local leaderstats = Player:WaitForChild("leaderstats")
if leaderstats.Money.Value < Items[Item].Price then return end
leaderstats.Money.Value -= Items[Item].Price
local NewItem = Items[Item].ItemPath:Clone()
NewItem.Parent = Player.Backpack
end
function Items.CheckPrice(Player, Item)
local leaderstats = Player:WaitForChild("leaderstats")
if leaderstats.Money.Value < Items[Item].Price then return false end
return true
end
return Items```
I only need it to be accessed by the client for the check price function and I don't really want to make a whole seperate module for it
the way i handled a shop for my game a while ago was to have a module that listed shop items that was usable by clients and server and have a separate server script that handled purchases
what bothers me about your solution is 1. why do you need the item path hardcoded when every path is just itemfolder[Item] 2. the client doesn't need access to that purchase function
why not
a module required by the client side won't be able to look for things on the server side so you'll have to do it on the server
I need the client to be able to check the prices using the price check function
The client can't access things in server storage so when it looks for things in severstorage it becomes an inf yield
I also dont really see how my item paths are hard coded
move the price check function with the table to a separate module and have the server handle purchasing and item distribution
cuz u could replace all that individually typing out the item path with ItemFolder[Items[Item]]
That just doesnt work
No I mean why not make a separate module
I was trying to make it as simple as possible but I ended up having to do it