--Saving Script
01 | local DSS = game:GetService( "DataStoreService" ) |
02 |
03 | local datastore = DSS:GetDataStore( "GeneralSaveData" , "Players" ) |
04 |
05 | function generateDataKey(player) |
06 | local ret = "uid_" .. player.userId |
07 | return ret |
08 | end |
09 |
10 | function generateDataTable(player) |
11 | local dataTable = { |
12 | Cash = player.leaderstats.Cash.Value |
13 | } |
14 | return dataTable |
15 | end |
This is the New Shop script
01 | local player = game.Players.LocalPlayer |
02 | local price = script.Parent.Parent.Price |
03 | local tools = game.ReplicatedStorage:WaitForChild( "Tools" ) |
04 | local tool = tools:FindFirstChild(script.Parent.Parent.ItemNameValue.Value) |
05 | local cash = player.leaderstats:WaitForChild( "Cash" ) |
06 | local Purchased 1 = script.Parent.Parent.Parent.Frame.Item 1. Purchased |
07 | local Purchased 2 = script.Parent.Parent.Parent.Frame.Item 2. Purchased |
08 | local Purchased 3 = script.Parent.Parent.Parent.Frame.Item 3. Purchased |
09 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
10 | local RemoteEvents = ReplicatedStorage.RemoteEvents |
11 | local Event = RemoteEvents.Buy |
12 |
13 | Event.OnClientEvent:Connect( function () |
14 | if cash.Value < price.Value then |
15 | print ( "NotEnough" ) |
This is the RemoteEventsScript in serverscriptService
01 | game.Players.PlayerAdded:connect( function (player) |
02 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
03 | local RemoteEvents = ReplicatedStorage.RemoteEvents |
04 | local Event = RemoteEvents.Buy |
05 | local Buy = player.PlayerGui:WaitForChild( "Gui" ).Main.Info.Buy |
06 | Buy.MouseButton 1 Click:Connect( function () |
07 | Event:FireClient(player) |
08 | print ( "Worked" ) |
09 | end ) |
10 | end ) |
All of your attempts to change the value should be on the server. You should be firing a remote event/remote function(if you want a gui response, go with remote function), then checking if they have the correct amount and subtracting the value on the server.
You also should be cloning the tool to the player on the server as well so it replicates for other players.
This should help you: Remote functions/events