Datastoreservice doesn't work but also doesn't give an error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to make a value that saves to a player.

  2. What is the issue? Include screenshots / videos if possible!
    i am new to datastoreservice and i am trying it to work now for over 6 hours. i watched alvinblox, devkings and avishals tuturiols about it but i just can figure it out, i also enabled studio API acces

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i searched in other posts on the devforum but i didn’t understand the answers or there wasn’t even a solution, i searched the developer hub but they don’t give that much info and as already said, i watched 3 different tuturials.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
it also doens’t give an error and it only prints “pcall 2 has started”. after that it doesn’t print anything

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You can watch the video maybe it can help you:

https://www.youtube.com/watch?v=n1UpT2csAzo

as i said i already watched devkings, alvingblox and anothers tuturial about datastore

Since you can’t solve this problem, feel free to provide the code you are having trouble with. Members of the Devforum will do their best to fix it.

1 Like

o sorry i taught i copied it but here it is:

local datastoreservice = game:GetService(“DataStoreService”)

local mydata = datastoreservice:GetDataStore(“mydata”)

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, erromessage = pcall(function()

	data = mydata:GetAsync(player.UserId,"-cash")

end)

if success then
	cash.Value = data
end

end)

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

local good, bad = pcall(function()
	print("pcall 2 has started")
	mydata:SetAsync(player.UserId.."-cash", player.leaderstats.cash.Value)
	print("pcall 2 is going to end")
end)
print("pcall 2 has ended")
if good then
	print("pcall 2 was good")
else
	print("pcall 2 gave an error")
end

end)

I believe when PlayerRemoving is fired, all of its children are destroyed.

1 Like

O how should i do it then? is there an event that fires before the players leaves or should i just make an autosave?

I’d store the value in another place like ServerStorage.

1 Like

o yea thank you i’ll try it now

this didn’t work too but i found out that the videos were outdated but thanks for your time