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

Is there something wrong with my autosave script? My game doesn't autosave

So I made a game: https://web.roblox.com/games/4916966006/Island-Hunter-Simulator-TEST?refPageId=9286e993-bd6c-4b90-811f-fffa7f488c3d

But there is no autosave.

So I tried to make an autosave and it didn't work, please check the script for me, thank you:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local data
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-coins")
	end)
	
	if success then
		coins.Value = data
	else
		print("There was an error whilst getting your data")
		warn(errormessage)
	end
end)

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

	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId"-coins", player.leaderstats.Coins.Value)
	end)
		
		if success then
			print("Player data successfully saved")
		else
			print("There was an error when saving data")
			warn(errormessage)
		end
	end

7 comments

0

Are there any errors that come?

0

no, there are no error message or anything in the output, but it still doesn't autosave

0

You have a pcall, what comes from that?

0

Or maybe I can test this other script I've made just in case:

0

Seems fine to me

0

Did you forget the end) for the player removing function?

0

No, I didn't forget any end)

1 answer

So I found out that I forgot to define what myDataStore and DataStoreService is, thank you guys!

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