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

The Data is not being saved, was there a typo?

I am trying to do a currency system

Script: local currencyName = "Coins" local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")

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

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

local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder

local ID = currencyName.."-"..player.UserId
local savedData = nil

pcall (function()
	savedData = DataStore:GetAsync(ID)
end)

if savedData ~= nil then
	currency.Value = savedData
	print("DataLoaded")
else
	currency.Value = 50
end

end)

game.Players.PlayerRemoving:Connect(function(player) local ID = currencyName.."-"..player.UserId DataStore:SetAsync(ID.player.leaderstats[currencyName].Value) end)

game:BindToClose(function()

for i,player in pairs(game.Players.GetPlayers()) do
	if player then
		player:Kick("Game shutting down")
	end
end

wait(5)

end)

Error: Attempt to nil with leaderstats

3 comments

0

Help!

0

You don't have a name for your currency..,

0

Wdym

1 answer

So basically, you didn't create a variable named currencyName and because of that, it's refusing to make a datastore for a nil value.

1 comment

0

The first is local currency name =......

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