#Module script cant be used on both client and server

1 messages · Page 1 of 1 (latest)

faint oracle
#

I have a module script that I want to use on the client and server though because of the module script trying to search for things in serverstorage it doesn't work on the client side

faint oracle
#

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

scenic moth
#

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

pallid hemlock
#

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

faint oracle
faint oracle
# scarlet fern why not

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

scenic moth
#

move the price check function with the table to a separate module and have the server handle purchasing and item distribution

scenic moth
scarlet fern
faint oracle