I’m trying to make a cart script for purchasing items, using FireClient and OnClientEvent.
Just a quick question, How would you be able to use variables across multiple scripts, so it can be used for a function on a different script?
I tried using _G. but i found out global variables used on ServerScripts can only be used on the same type, and can’t be used on LocalScripts.
ServerScript
--To call values
local GoToCart = game:GetService("ReplicatedStorage"):WaitForChild("ItemToCart")
local InsertService = game:GetService("InsertService")
local ClickDetect = script.Parent.ClickDetector
Manniquin = script.Parent
_G.ShirtNum = Manniquin.ShirtID.Value
_G.PantNum = Manniquin.PantID.Value
_G.Pants = Manniquin.Pants
_G.Shirts = Manniquin.Shirt
_G.PantAsset = InsertService:LoadAsset(_G.PantNum)
_G.ShirtAsset = InsertService:LoadAsset(_G.ShirtNum)
-- Change Items to NumberValues
if _G.ShirtNum or _G.PantNum > 0 then
_G.Pants.PantsTemplate ="http://www.roblox.com/asset/?id=".. _G.PantAsset
_G.Shirts.ShirtTemplate = "http://www.roblox.com/asset/?id=".. _G.ShirtAsset
wait(0.2)
end
--For Adding Items to the Cart
function AddItem()
GoToCart:FireClient()
end
ClickDetect.MouseClick:Connect(AddItem)
and the Localscript
waitHuh = game:GetService("ReplicatedStorage"):WaitForChild("ItemToCart")
Items = script.Parent
function Poro(values,tryshr,valuep,tryp)
if values ~= "" then
if Items.Item1.Image == "" then
Items.Item1.Image = tostring("http://www.roblox.com/Thumbs/Asset.ashx?format=png&width=100&height=100&assetId=" .. values)
Items.Item1.ClothingID = values
Items.Item1.tryvalue = tryshr
Items.Item1.Type = "Shirt"
end
end
waitHuh.OnClientEvent:Connect(Poro)
Yea, it worked. I modified the ServerScript a little bit. I noticed that the client wasn’t receiving the arguments/parameters since a few of the values were not even loaded in correctly.
local PantAsset = InsertService:LoadAsset(PantNum)
local ShirtAsset = InsertService:LoadAsset(ShirtNum)
local ShirtRaw = ShirtAsset.Pants.PantsTemplate
local PantRaw = PantAsset.Pants.PantsTemplate
local ShirtID = ShirtRaw:match("%d+")
local PantID = PantRaw:match("%d+")
-- Change Items to NumberValues
if ShirtNum or PantNum > 0 then
print(ShirtID)
Pclothing.PantsTemplate = "rbxassetid:/".. PantID
sclothing.ShirtTemplate = "rbxassetid:/".. ShirtID
wait(0.2)
end
--For Adding Items to the Cart
ClickDetect.MouseClick:Connect(function(player)
local values = ShirtNum
local tryshr = ShirtID
local valuep = PantNum
local tryp = PantID
wait(0.5)
GoToCart:FireClient(player, values, tryshr, valuep, tryp)
end)
It looks almost the same but I added a few more variables to separate the ID from the actual asset URL. Though using modules would have worked regardless.