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

My datastore doesn't work and I did everything correctly? It suddenly stopped working.

My datastore doesn't work. I have done everything right. This is the script

local Datastore = game:GetService("DataStoreService"):GetDataStore("pixel-DS3")

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

local Key = "Player-ID:" .. player.userId

local leaderstats = Instance.new("Folder", player)

leaderstats.Name = "leaderstats"

local Coins = Instance.new("NumberValue", leaderstats)

Coins.Name = "Coins"

Coins.Value = 0

  

local Strength = Instance.new("NumberValue", leaderstats)

Strength.Name = "Strength"

Strength.Value = 0

local Rebirths = Instance.new("NumberValue", leaderstats)

Rebirths.Name = "Rebirths"

Rebirths.Value = 1

-- GetAsync

local GetSave = Datastore:GetAsync(Key)

if GetSave then

Coins.Value = GetSave[1]

Strength.Value = GetSave[2]

Rebirths.Value = GetSave[3]

print("Data loaded for " .. player.Name)

else

local Numbers = {Coins.Value, Strength.Value, Rebirths.Value}

Datastore:SetAsync(Key, Numbers)

print("Data Saved for " .. player.Name)

end

end)

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

local Key = "Player-ID:" .. player.userId

local ValuesToSave = {player.leaderstats.Coins.Value, player.leaderstats.Strength.Value, player.leaderstats.Rebirths.Value}

Datastore:SetAsync(Key, ValuesToSave)

print("Data Saved for " .. player.Name)

end)

3 comments

0

If it was "right" it would work. Also Lua is not an acronym so it shouldn't be all in caps...

0

You should use pcall() since DataStore fails sometimes.

0

the site is having issues so its ----probably---- not gonna work, idk i dont work with datastore anyways

1 answer

Make the part where you get points Filtering Enabled.

What this means?

Well, FE is pretty simple once you get the hang of it. I will take you though the proper steps. So, the part you want to be FE is the time you get points. You need a RemoteEvent, a controlling script and the datastore script.

First, add a RemoteEvent into Replicated Storage. After this, rename it to whatever you want. I will name it Tutorial for now. Now add a script into ServerScriptService, and insert the following code.

game.ReplicatedStorage.Tutorial.OnServerEvent:Connect(function()
--Enter code to give money/cash/rebirth here!
end)

In between the function and the End, add the code that adds the currency. Now delete the part where it adds the currency in your original script that adds the currency, and change that code too:

game.ReplicatedStorage.Tutorial:FireServer()

--Spiral. Tell me if something doesn't work, or you don't understand!

3 comments

0

Hope this helps! If it does, please mark this as answered!

0

Oh god, not an AlvinBlox video.

0

Doesn't work

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