Hello, everyone. I am having a lot of trouble. So, I have a working DataStore with preset Data in it.. so, I am trying to make a PlayerList, Chat GUI, etc. based on the saved Data that the player has, such as the RankId (their In-Game Chat/PlayerList logo). But, when I try things ingame to make the logo change based on their Experience, it doesn't work out. Here is my code.. I don't know what to do. D;
function onPlayerEntered(newPlayer) --Clone Data-- local vs = script:WaitForChild("Data"):clone() vs.Parent = newPlayer --Setup Intial Data-- local Stats = vs:GetChildren() local S1 = {} for i=1,#Stats do local n = Stats[i].Name S1[n] = Stats[i].Value end --Get Data-- if newPlayer.Name ~= "Player" then local DataStore = game:GetService("DataStoreService"):GetDataStore(newPlayer.userId) if DataStore:GetAsync("Stats") == nil then DataStore:SetAsync("Stats", S1) end S1 = DataStore:GetAsync("Stats") end --Safely Load Data-- local vv = vs:GetChildren() for i=1,#vv do local n = vv[i].Name --print(S1[n]) if S1[n] ~= nil then vv[i].Value = S1[n] end end end game.Players.PlayerAdded:connect(onPlayerEntered) for _,player in pairs(game.Players:GetChildren()) do onPlayerEntered(player) end game.Players.PlayerRemoving:connect(function(p) --Save Data-- local DataStore = game:GetService("DataStoreService"):GetDataStore(p.userId) local stats = p.Data:GetChildren() local s1 = {} for i=1,#stats do local n = stats[i].Name s1[n] = stats[i].Value end DataStore:SetAsync("Stats",s1) --print("Saved "..p.Name) end)
That is just saving the Data. I tried adding stuff in there to get my goal, but failed. Here is another script I made to try configuring the Data:
function onPlayerEntered(newPlayer) local vs = script.Parent.Parent.Parent:WaitForChild("Data") if vs.Data.Inormation.Experience.Value >= 0 and vs.Data.Inormation.Experience.Value < 500 then vs.Data.Information.Level.Value = 0 vs.Data.Information.RankName.Value = "Serf" vs.Data.Information.RankId.Value = 336513453 end end game.Players.PlayerAdded:connect(onPlayerEntered) for _,player in pairs(game.Players:GetChildren()) do onPlayerEntered(player) end
Please help. I know what I am saying is confusing.. but I don't know how to explain it.