Well there is actually 2 problem
First of all:
You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to load a saved table when player joins -
What is the issue? Include screenshots / videos if possible!
I Don’t know how to? -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve read a few topics about that but they didn’t really helped
Okay so.
after players claim a rewards I am putting name of the reward to table so they can’t claim them again.
I managed the save the table and name of rewards but I can’t load it back
local players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local GameDataName = DataStore:GetDataStore("WELLOTHEREFRIEND112S4")
local part = workspace.TestPart1
local Remotes = game:GetService("ReplicatedStorage")
local DailyRewards = require(game:GetService("ServerScriptService"):WaitForChild("DailyRewards"))
local ClaimedRewards = {}
local DailyRewardsChecker = {}
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
coins.Value = 3000
local values = Instance.new("Folder",player)
values.Name = "Values"
local Dailycooldown = Instance.new("IntValue",values)
Dailycooldown.Name = "DailyCooldown"
local succes,Data = pcall(function()
return GameDataName:GetAsync(player.UserId)
end)
if succes then
if Data then
-- if player is not new
--ClaimedRewards[player.UserId]={}
DailyRewardsChecker[player.UserId] = {TimePlayed = Data["TimePlayed"], PlayerJoinOsTime= Data["PlayerJoinOsTime"]}
print("NotNewPlayer")
for k, d in pairs(Data) do
if k == "RewardsTable" then
print("Welp")
else
if type(d) == "table" then
for n, v in pairs(d) do
warn(k,n,v)
if player[k][n]:IsA("Folder") then -- Is a Folder
else -- is a Value
player[k][n].Value = v
end
end
end
end
print(Data)
end
else
ClaimedRewards[player.UserId] = {}
warn("NewPlayer")
DailyRewardsChecker[player.UserId] = {TimePlayed = 0, PlayerJoinOsTime= os.time()}
end
--Something Wrong with DataStore script or servers are down.
end
end)
players.PlayerRemoving:Connect(function(player)
local coins = player.leaderstats.Coins.Value
local Dailycooldown = player.Values.DailyCooldown.Value
local DataTable ={
["leaderstats"] = {Coins = coins},
["Values"] = {DailyCooldown = Dailycooldown},
["ClaimedRewards"] = ClaimedRewards[player.UserId],
["DailyRewardChecker"] = DailyRewardsChecker[player.UserId]
}
local success,data = pcall(function()
return GameDataName:SetAsync(player.UserId,DataTable)
end)
if success then
print(DataTable)
else
warn("DataSavingError")
end
end)
Remotes.RewardCheck.OnServerEvent:Connect(function(player,ButtonName)
warn("I got the".. ButtonName)
if player.Values.DailyCooldown.Value < math.floor(os.time()/86400) then
if not table.find(ClaimedRewards[player.UserId],ButtonName) then
table.insert(ClaimedRewards[player.UserId],ButtonName)
else
print("RewardAlreadyClaimed")
end
end
end)
Everytime I tried to load data I got this errors
DailyRewardChecker is not a valid member of Player
ClaimedRewardsis not a valid member of Player
Error Shows this lines
for k, d in pairs(Data) do
if k == "RewardsTable" then
print("Welp")
else
if type(d) == "table" then
for n, v in pairs(d) do
warn(k,n,v)
if player[k][n]:IsA("Folder") then --Error Shows This line
else -- is a Value
player[k][n].Value = v
end
end
end
end
end
the second problem is. even if I can able to load it ClaimedRewards[Player.UserID]={} return an empty table like no rewards claimed before How can I load the one data saved?