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

My game isn't saving data, how can I fix this critical issue?

I have a datastore that is supposed to save the points of the player, for some reason, it doesn't work and because it is wrapped in a pcall, it does not send an error to fix.

Here the points script: (Works)


game.Players.PlayerAdded:connect(function(plr)
	
	
	local ls = plr:WaitForChild("leaderstats")
	
	local rank = Instance.new("IntValue",ls)
	rank.Name = "Points"
	rank.Value = 0
while true do
	rank.Value = rank.Value + 5
	wait(5)
end
end)

Here is the data script: (Does not work)

local dataStores = game:GetService("DataStoreService"):GetDataStore("ExtolDataStore")
local players = 0

game.Players.PlayerAdded:connect(function(plr)
	players = players + 1
	
	local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value
	
	
	local player_data

pcall(function()
	 player_data = dataStores:GetAsync("user_"..plr.UserId,points)
end)

if player_data ~= nil then
	points = player_data else
	points = 0
end

end)


local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:connect(function(plr)
	local points = plr:WaitForChild("leaderstats"):WaitForChild("Points").Value
	
	pcall(function()
		dataStores:SetAsync("user_"..plr.UserId,points)
		print("Saved "..plr.Name.."'s Data")
		players = players - 1
		bindableEvent:Fire()
	end)
	
	game:BindToClose(function()
	while players > 0 do
		bindableEvent.Event:Wait()
	end
	end)
end)

Thank you to anyone who can help.

1 comment

0

Is the Value property not updating when your points variable is updated?

1 answer

  1. Why are you using pcall in the first place?
  2. You'll have to handle saving and all that in the pcall it self, if this doesn't work then don't use pcall............

1 comment

0

What a half assed response.

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