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

Datastores. leaderstats is not a valid member of Player?

Hello. I'm trying to use Datastores to save the data of the player but I'm getting this error: 13:23:18.407 - leaderstats is not a valid member of Player

My code:~~~~~~~~~~~~~~~~~

local DataStoreService = game:GetService("DataStoreService")

local MyDataStore = DataStoreService:GetDataStore("MyDataStore")

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

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

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

local data
local success, errormessage = pcall(function()
	data = MyDataStore:GetAsync(player.UserId.."-cash")
end)

if success then
	cash.Value = data
else
	print("There was an error while getting your data")
	warn(errormessage)
end

end)

game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() MyDataStore:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value) end) if success then print("Player data succesfully saved") else print("There was an error when saving your data") warn(errormessage) end

end)



1 answer

✓ Accepted answer

It is because, look at MyDataStore:SetAsync(player.UserId-.."cash", player.leaderstats.Cash.Value) look that you put leaderstats instead of 'Leaderstats. Please change lowercase L to uppercase L. leaderstats must become Leaderstats.

Hope this helps.

3 comments

0

okay. thank you

0

can you accept my answer? thank you :)

0

Done

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