So this local script is sending the serverscript the item the player wants to buy
local replicatedStorage = game:GetService(“ReplicatedStorage”)–Defines replicated storage
local selectedItem = script.Parent.Parent.Parent:WaitForChild(“SelectedItem”)–Defines what selectedItem is
local success--Variable
script.Parent.MouseButton1Click:Connect(function()
success = false--Makes success false
if selectedItem.Value ~= nil then--If the value isn't equal to nil
selectedItem.Value = script.Parent.Parent.Name
success = replicatedStorage.CheckSale:InvokeServer(selectedItem.Value)--Make a request to the remote function
end
if success then
print("Purchased!")
else
print("Purchase Failed!")
end
end
But what is this serverscript doing? I don’t know what item is because I never defined it.
local replicatedStorage = game:GetService("ReplicatedStorage")--Defines replicated storage
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems")--Defines the items in ServerStorage
replicatedStorage.CheckSale.OnServerInvoke = (function(player,item)--Responds to the remote function request
local price = shopItems[item].Points.Value--Defines the price of the item
if player.leaderstats.Points.Value >= price then--Check to see if the player has enough money
player.leaderstats.Points.Value = player.leaderstats.Points.Value - price--Subtracts the price
local gear = shopItems[item[item]]:Clone()--Clones the item they bought
gear.Parent = player.Backpack--Put the clone in their backpack
return true
else
return false
end
end)