#correct yielding

1 messages · Page 1 of 1 (latest)

sturdy orchid
#

i have replica and profile service, but dont have correct yielding

local RS = game:GetService("ReplicatedStorage")
local SS = game:GetService("ServerStorage")
local SSS = game:GetService("ServerScriptService")
local DataMgr = require(SSS.Data.DataManager)
local InvMgr = require(SSS.Data.InventoryManager)

local function HandleBuyItemEvent(player: Player, item: string)
    local itemInfo = require(RS.Items[item])
    local plrProfile = DataMgr.Profiles[player]    
    if itemInfo == nil or plrProfile == nil then return end
    if itemInfo.DevItem then return end
    
    if (InvMgr:HasItem(player, item)) then
    elseif (plrProfile.Data.Cash >= itemInfo.Price) then
        DataMgr:RemoveCash(player, itemInfo.Price)
        DataMgr.Replicas[player]:Set({"Inventory", item}, 1)
    end
end

RS.Remotes.BuyItem.OnServerEvent:Connect(HandleBuyItemEvent)

i need easy and good practice yielding for scripts like this (not to return if plrProfile == nil). can smb explain best way to do it? i know abt promises but they seem too complicated for my game

sturdy orchid
#

.