I need help with making this shopgui

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

4 Likes

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.

2 Likes

I tried to do a server script with a remote function but when I try to send the values it keeps erroring

You don’t need to do a remote function. You need to do a remote event.

A remote function is used to retrieve something from the server. Basically the client is asking the server for information.

A remote event fires an event to the server, once it’s received on the server, code will run.

In this case you just need a remoteEvent to fire from the client to the server and call the buyitem function from there.

2 Likes

I actually tried a remote event before a remote function and it also keep erroring I will try to use a remote event again and tell you the error

What’s the error and send the code where the error is on.

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)

line 4

2 Likes

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)

BuyItemEvent:FireServer(Player,Item,CostOfItem) this is wrong. You don’t need to send the player arguement to the server.

Because when the server receives a remote event from the client the player (client) is always passed on automatically.

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.

Remove it from the client not the server.

1 Like

Thanks for the fix!
(30 words requirement!)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.