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

how can I change my local script to fit this datastore?

Asked by 5 years ago

I'm pretty sure this is the problem. I made a datastore script that goes like this:

01local DataStoreService = game:GetService("DataStoreService")
02local MyDataStore = DataStoreService:GetDataStore("myDataStore")
03 
04 
05game.Players.PlayerAdded:Connect(function(player)
06 
07    local leaderstats = Instance.new("Folder")
08    leaderstats.Name = "leaderstats"
09    leaderstats.Parent = player
10 
11    -- Display an 'IntValue' on leaderboard
12    local cash = Instance.new("IntValue")
13    cash.Name = "Cash"
14    cash.Parent = leaderstats
15 
View all 56 lines...

If I play my game on Roblox (not studio) I am able to save the value of cash if I type a command from HD admin.

1Change me Cash 1000

I leave the game and this is saved and remains when I come back. However, I have a localscript in StarterPlayerScripts that is:

1while true do
2 wait(10)
3game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 10
4  end

The 1000 will go (ex.1040) and it won't save.
I can use the admin command to change the value to 1040 and it saves. What can I do to fix this?

1 answer

Log in to vote
1
Answered by 5 years ago

You have to use remote events to do this as you have got filtering enabled and anything you do on the client won't save. Therefore you have to use remote events for the server to see the change. Read this article here

Ad

Answer this question