Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

data store service wont work?

i have a script,

require(script:WaitForChild('Coins'))

and then i have a module script inside ,

local module = {} local DataStore = game:GetService("DataStoreService"):GetDataStore("Tutorial3816310153")

local StartingLevel = 0

game.Players.PlayerAdded:connect(function(plr)

local Stats = plr:FindFirstChild("leaderstats")

local Level = Stats.Coins

local SavedLevel = DataStore:GetAsync(plr.userId .. "-Coins") if SavedLevel ~= nil then Level.Value = SavedLevel end

end)

game.Players.PlayerRemoving:connect(function(plr) local id = plr.userId local LevelValue = plr.leaderstats.Coins.Value DataStore:SetAsync(id.."-Coins", LevelValue) end)

return module

BuT It wOn'T WoRk

2 comments

0

Which part does not work, obtaining the value or saving the value? Also if the output throws any errors please add them aswell

0

i does not have an error but it wont work

1 answer

✓ Accepted answer

I am making a simple DataStore that saves you money in leaderstats. It isn’t saving for some reason but it is loading fine and I can’t work out why.

Here is the code: Server Script in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remotes = ReplicatedStorage:WaitForChild("Remotes") local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("StatsSave")

local DefultData = { Money = 100; } -- Load Data game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player

local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats

local Data = DataStore:GetAsync(Player.UserId)

if Data then
	Money.Value = Data
else
	Money.Value = DefultData.Money
end

end)

-- Save Data local function SaveData(Player) local Money = Remotes.MoneySave:InvokeClient(Player) DataStore:SetAsync(Player.UserId, Money) end

game.Players.PlayerRemoving:Connect(SaveData)

LocalScript in StarterPlayerScripts:

local leaderstats = script.Parent.Parent:WaitForChild("leaderstats") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local function SendData() return leaderstats.Money.Value end

Remotes.MoneySave.OnClientInvoke = SendData I have a RemoteFunction in ReplicatedStorage in a folder called Remotes and the RemoteFunction is called MoneySave.

Note:I have Studio API Services turned on and I get no errors.

Thank you in advanced.

This discussion is preserved as it was. New answers, comments, and votes are closed.