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

How come this script wont save even though it has 3 saving things?

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("NCSaveSystem")
local ds2 = datastore:GetDataStore("BoogieSaveSystem")
local ds3 = datastore:GetDataStore("RebirthSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local NC = Instance.new("IntValue", folder)
 NC.Name = "NoseCoins"
 local boogers = Instance.new("IntValue", folder)
 boogers.Name = "Boogies"
 local Rebirths = Instance.new("IntValue", folder)
 Rebirths.Name = "Rebirths"
 
 NC.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, NC.Value)
	
 boogers.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, boogers.Value)
	
 Rebirths.Value = ds3:GetAsync(plr.UserId) or 0
 ds3:SetAsync(plr.UserId, Rebirths.Value)	
 
 NC.Changed:connect(function()
  ds1:SetAsync(plr.UserId, NC.Value)
 end)
 
 boogers.Changed:connect(function()
 ds2:SetAsync(plr.UserId, boogers.Value)
		
 Rebirths.Changed:connect(function()
 ds3:SetAsync(plr.UserId, Rebirths.Value)
 end)
 end)
end)

I have been trying to do an actual working save script for about 2 years now. HOW THE HELL DOES EVERYBODY GET THEIRS TO SAVE???!!!!!!

3 comments

0

are you testing your code in studio? if so, enable api services

0

i did, then studio lagged so hard i had to delete it with task manager

0

still wont work though

1 answer

First question, why are you using 3 datastores? Also, you should be using NumberValues, not IntValues.

You also don't reference any of the DataStores in your script, you just save them as variables.

Here, let me fix your code.

local dss = game:GetService('DataStoreService')
local datastore = dss:GetDataStore('putsomethingrandomhere')

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player

local nosecoins = Instance.new('NumberValue')
nosecoins.Name = 'Nose Coins'
nosecoins.Value = 0 or datastore:GetAsync(player.UserId)['Nose Coins']
nosecoins.Parent = leaderstats

local boogers = Instance.new('NumberValue')
boogers.Name = 'Boogies'
boogers.Value = 0 or datastore:GetAsync(player.UserId).Boogies
boogers.Parent = leaderstats

local rebirths = Instance.new('NumberValue')
rebirths.Name = 'Rebirths'
rebirths.Value = 0 or datastore:GetAsync(player.UserId).Rebirths
rebirths.Parent = leaderstats

game.Players.PlayerRemoving:Connect(function()
datastore:SetAsync(player.UserId, {

['NoseCoins'] = player.leaderstats['Nose Coins'].Value
['Boogies'] = player.leaderstats.Boogies.Value
['Rebirths'] = player.leaderstats.Rebirths.Value

})

That should work, LMK if there are any problems when you test it!

5 comments

0

On line 28, put a space inbetween nose and coins

0

Error: Expected "}" to close "{" at line 26, got "="

0

does not create leaderstats, but it would if there was no erros

0

I'll take a look into the error.

0

My bad! I must've been tired or something when typing the script. Here's the fixed version: https://pastebin.com/raw/rnBczWQk

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