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

Having some issues with data store, how can I fix them? [Solved]

So I made this simple data store which saves an IntValue, however, upon testing it, it prints that my data was found. Moreover, as I checked the value, nothing changed (meaning the IntValue's value remained at zero). I'm not entirely sure as to what I'm doing wrong but if anyone could show me the issues, I would greatly appreciate it!

Code:

local DataStore = game:GetService("DataStoreService")
local CHPT_Data = DataStore:GetDataStore("CHPT")
game.Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder",player)
	Folder.Name = "CHPT_Info"
	local Info_Val = Instance.new("IntValue",Folder)
	Info_Val.Name = "CHPT"
	local DT = nil
	local Suc, Fail = pcall(function()
		DT = CHPT_Data:GetAsync(player.UserId)
		end)
	if not Suc then
		Info_Val.Value = 1
		print("no data found")
	else
		Info_Val.Value = DT
		print("data found!")
		end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Folder = player:FindFirstChild("CHPT_Info")
	local Info_Val = Folder:WaitForChild("CHPT")
	local Suc, Fail = pcall(function()
		CHPT_Data:SetAsync(player.UserId, Info_Val.Value)
	end)
	if Suc then
		print("Data saved")
	else
		print("Data not saved!")
	end
end)

1 answer

First of all make sure that Roblox studio api access is turned on secondly

There are 3 reasons why using PlayerRemoving event will not work when saving a player:

The last player leaves

The developer manually shut them down via the game page

A network error is encountered and the server is forced to shut down

when ur testing in studio without server with mutliple players always the first issue happens

This article explains how u should save when those actions arise

1 comment

0

I'm already aware of all this, however, I've found an alternate solution to my issue, but thanks!

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