Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My cash is not saving after I leave the game. This is all in a local script. How do i save it?

Asked by 5 years ago
Edited 5 years ago

--Saving Script

01local DSS = game:GetService("DataStoreService")
02 
03local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
04 
05function generateDataKey(player)
06    local ret = "uid_" .. player.userId
07    return ret
08end
09 
10function generateDataTable(player)
11    local dataTable = {
12     Cash = player.leaderstats.Cash.Value
13    }
14    return dataTable
15end
View all 41 lines...

This is the New Shop script

01local player = game.Players.LocalPlayer
02local price = script.Parent.Parent.Price
03local tools = game.ReplicatedStorage:WaitForChild("Tools")
04local tool = tools:FindFirstChild(script.Parent.Parent.ItemNameValue.Value)
05local cash = player.leaderstats:WaitForChild("Cash")
06local Purchased1 = script.Parent.Parent.Parent.Frame.Item1.Purchased
07local Purchased2 = script.Parent.Parent.Parent.Frame.Item2.Purchased
08local Purchased3 = script.Parent.Parent.Parent.Frame.Item3.Purchased
09local ReplicatedStorage = game:GetService("ReplicatedStorage")
10local RemoteEvents = ReplicatedStorage.RemoteEvents
11local Event = RemoteEvents.Buy
12 
13    Event.OnClientEvent:Connect(function()
14        if cash.Value < price.Value then
15            print("NotEnough")
View all 41 lines...

This is the RemoteEventsScript in serverscriptService

01game.Players.PlayerAdded:connect(function(player)
02    local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local RemoteEvents = ReplicatedStorage.RemoteEvents
04local Event = RemoteEvents.Buy
05local Buy = player.PlayerGui:WaitForChild("Gui").Main.Info.Buy
06    Buy.MouseButton1Click:Connect(function()
07        Event:FireClient(player)
08        print("Worked")
09    end)
10end)
0
My bad, i answered that its because you are not loading the value upon joining, but i just didnt see the "View all 41 lines" tab lol i dont usually come on this site. Could it be because your script tries to load and input the data before the intvalue is generated? *edit Scriptulus 30 — 5y
0
he trys to do server stuff with local script User#27824 0 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
There is also a broplem with closing the game right he is not binding to close.. Luka_Gaming07 534 — 5y
0
That's not what they are asking. Bind to close is for shutdown, and i would use that for a soft shutdown. coolboy6786543 113 — 5y
0
CoolBoy how would i set up the remote event GunzerkingBeast21 -4 — 5y
0
My values are still not saving GunzerkingBeast21 -4 — 5y
0
When they purchase things fire a remote event and subtract the values/give them the item on the server. coolboy6786543 113 — 5y
Ad

Answer this question