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)