Datastore not saving data

I am trying to make a data store save an int value in the playergui but it’s not saving and there is no error

script

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("PlayerData2")

local function onPlayerJoin(player)
	local playerUserId = "Player_" .. player.UserId
	local data = playerData:GetAsync(playerUserId)

	if data then
		print("Got player data")
		player.PlayerGui:WaitForChild("QuestGui").quest.ScrollingFrame.quest1.fish.Value = data
	else
		game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("QuestGui").quest.ScrollingFrame.quest1.fish.Value = 0
	end
end

local function onPlayerExit(player)
	local success, err = pcall(function()
		print("DataSaved")
		local playerUserId = "Player_" .. player.UserId
		playerData:SetAsync(playerUserId, game.Players:FindFirstChild(player.Name).PlayerGui.QuestGui.quest.ScrollingFrame.quest1.fish.Value)
	end)

	if not success then
		warn('Could not save data!')
	end

end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)

Ok hold, awn!
I suggest you re-making the system in a different approach, place a folder inside your serverscript and make a boolvalue with the quest name.

Then inside the boolvalue add in, Finished value, (bool value) and
An Activated value, (bool value).

Then you would clone that quest data and assign it to the player like so.


game.Players.PlayerAdded:Connect(function(plr)
      local QuestData = script.QuestData
       QuestData:Clone()
       QuestData.Parent =  plr
end)

Then you can make the script through that instead of getting data from a the a playerGUI which exploiters can easily exploit. (same with this system though you would add security.)

1 Like

Ok thank you really appreciated

1 Like