I made two simple scripts a clientcore script thats goes into the shop frame and a shopmodule script however when the money is removed it is only removed on the player object and the money value stays the same on the server can you please help?
Client script
local IsAItemSelectedValue = ItemInfo:WaitForChild("IsAItemSelected?")
local ShopButtionScrollingFrames = ShopFrame:WaitForChild("ShopButtionScrollingFrame")
local PressedButtion
local Collection = game:GetService("CollectionService")
local Player = game.Players.LocalPlayer
local ShopModules = require(game.ReplicatedStorage.ShopModules)
local ShopButtions = Collection:GetTagged("ShopButtions")
local function setupButtions(Buttion)
local IconOfItem = Buttion:WaitForChild("Icon")
local NameOfItem = Buttion:WaitForChild("NameOfItem")
local DescriptionOfItem = Buttion:WaitForChild("ItemDescription")
local Item = Buttion:WaitForChild("ItemThatTheButtionsells")
local CostOfItem = Buttion:WaitForChild("Cost")
local BaldiCoins = Player.leaderstats.BaldiCoins
Buttion.MouseButton1Click:Connect(function()
IconOfIteminfo.Image = IconOfItem.Value
NameOfIteminfo.Text = NameOfItem.Value
DescriptionOfIteminfo.Text = DescriptionOfItem.Value
CostOfItemInfo.Text = CostOfItem.Value
IsAItemSelectedValue.Value = true
PressedButtion = Buttion
end)
BuyButtion.MouseButton1Click:Connect(function()
if IsAItemSelectedValue.Value == true and BaldiCoins.Value >= CostOfItem.Value then
ShopModules.buyitem(Player,Item.Value,CostOfItem.Value)
end
end)
end
local function ShopButtionAdded(Buttion)
setupButtions(Buttion)
end
-- Connect existing shopbuttions
for _, model in pairs(ShopButtions) do
setupButtions(model)
end
-- Connect new shopbuttions
Collection:GetInstanceAddedSignal("ShopButtions"):Connect(ShopButtionAdded)
Module Script:
local module = {}
function module.buyitem(Player,ShopItem,Cost)
Player.leaderstats.BaldiCoins.Value = Player.leaderstats.BaldiCoins.Value - Cost
print("yes")
print(ShopItem)
end
return module
The client side script is stored into the shopframe and the module script is stored in replicated storage
That’s because you are changing the money value from the client. The server cannot detect changes made on the client so you should change it so the server subtracts the coins from the player. This would be very exploit vulnerable because an exploiter can run the buyitem function and give themselves lots of coins.
Exploiters can access scripts on the client and fire functions or remote events.
Here is the error: ServerScriptService.ShopScript (ServerSide):4: attempt to compare string <= number
Script Code:
local BuyItemEvent = game.ReplicatedStorage.ShopEvents:WaitForChild("ItemPurchased")
BuyItemEvent.OnServerEvent:Connect(function(Player,ShopItem,CostOfItem)
if Player.leaderstats.BaldiCoins.Value >= CostOfItem.Value then
print("yes")
Player.leaderstats.BaldiCoins.Value = Player.leaderstats.BaldiCoins.Value - CostOfItem.Value
print(ShopItem.Value)
end
end)
Make sure Player.leaderstats.BaldiCoins.Value >= CostOfItem.Value both values here are numbers and are you sure this is the right line because the error says <= and this code says >=
Okay so I used the print functions and it turns out the variables are mixed up!
Player variable is indeed a player whoever
ShopItem Variable is also the player object and costofItem variable IS THE SHOPITEM VARIABLE
Here is the line used to Fire The remote event BuyItemEvent:FireServer(Player,Item,CostOfItem)
But How would I be able to know if a player haves enough coins to purchase a item and remove coins from the serverside without exploiters messing stuff up?
Okay I removed the player variable but now the script thanks the Shopitem variable is the player!
Error: Value is not a valid member of Player “Players.Puma_incredible”
Well on the server you have access to the leaderstats assuming you made them on the server as they should be. So the server should change any values within them. Exploiters will only look for vulnerablities in your code where they can fire functions or remote events on the client to cheat. You can make remote events more by adding checks for certain things but I wont get into that you can do your own research.