This is the first topic I’ve ever created; please forgive me if anything is wrong or not up-to-par.
The purpose of this topic is to:
- See if this is an inefficient way of using datastores
- See if is any better ways of accomplishing what I already have
- Be warned about any errors or exploits that I may not have accounted for
Also, if my coding seems “unprofessional”, my apologies in advance
(any suggestions on improving the way I do anything is gladly accepted)
local datastore = game:GetService("DataStoreService")
local DATA_lvl = datastore:GetDataStore("...")
local DATA_coins = datastore:GetDataStore("...")
local DATA_gems = datastore:GetDataStore("...")
local DATA_wins = datastore:GetDataStore("...")
local DATA_xp = datastore:GetDataStore("...")
local DATA_xpn = datastore:GetDataStore("...")
local DATA_rebirths = datastore:GetDataStore("...")
local DATA_colors = datastore:GetDataStore("...")
local DATA_trail = datastore:GetDataStore("...")
function savedata(dataname, playerid, value)
datastore:GetDataStore(dataname):SetAsync(playerid, value)
end
game.Players.PlayerAdded:connect(function(player)
local playerconfig = player:WaitForChild("PlayerConfiguration")
local leaderstats = player:WaitForChild("leaderstats")
local level = leaderstats:WaitForChild("Level")
local coins = leaderstats:WaitForChild("Coins")
local gems = playerconfig:WaitForChild("Gems")
local wins = leaderstats:WaitForChild("Wins")
local xp = playerconfig:WaitForChild("xp")
local xpneeded = playerconfig:WaitForChild("xpneeded")
local rebirths = leaderstats:WaitForChild("Rebirths")
local colornumbers = game:GetService("ReplicatedStorage"):WaitForChild("PeoplesColors"):WaitForChild(player.Name)
local trail = game:GetService("ReplicatedStorage"):WaitForChild("PeoplesTrails"):WaitForChild(player.Name)
repeat wait() until trail
if DATA_coins:GetAsync(tostring(player.userId)) ~= nil then
coins.Value = DATA_coins:GetAsync(tostring(player.userId))
end
if DATA_gems:GetAsync(tostring(player.userId)) ~= nil then
gems.Value = DATA_gems:GetAsync(tostring(player.userId))
end
if DATA_wins:GetAsync(tostring(player.userId)) ~= nil then
wins.Value = DATA_wins:GetAsync(tostring(player.userId))
end
if DATA_xpn:GetAsync(tostring(player.userId)) ~= nil then
xpneeded.Value = DATA_xpn:GetAsync(tostring(player.userId))
end
if DATA_xp:GetAsync(tostring(player.userId)) ~= nil then
xp.Value = DATA_xp:GetAsync(tostring(player.userId))
end
if DATA_rebirths:GetAsync(tostring(player.userId)) ~= nil then
rebirths.Value = DATA_rebirths:GetAsync(tostring(player.userId))
end
if DATA_colors:GetAsync(tostring(player.userId)) ~= nil then
colornumbers.Value = Color3.new(DATA_colors:GetAsync(tostring(player.userId)).r,DATA_colors:GetAsync(tostring(player.userId)).g,DATA_colors:GetAsync(tostring(player.userId)).b)
end
if DATA_lvl:GetAsync(tostring(player.userId)) ~= nil then
level.Value = DATA_lvl:GetAsync(tostring(player.userId))
end
if DATA_trail:GetAsync(tostring(player.userId)) ~= nil then
trail.Value = DATA_trail:GetAsync(tostring(player.userId))
end
end)
game.Players.PlayerRemoving:connect(function(player)
local playerconfig = player:WaitForChild("PlayerConfiguration")
local leaderstats = player:WaitForChild("leaderstats")
local level = leaderstats:WaitForChild("Level")
local coins = leaderstats:WaitForChild("Coins")
local gems = playerconfig:WaitForChild("Gems")
local wins = leaderstats:WaitForChild("Wins")
local xp = playerconfig:WaitForChild("xp")
local xpneeded = playerconfig:WaitForChild("xpneeded")
local rebirths = leaderstats:WaitForChild("Rebirths")
local colornumbers = game:GetService("ReplicatedStorage"):WaitForChild("PeoplesColors"):WaitForChild(player.Name)
local trail = game:GetService("ReplicatedStorage"):WaitForChild("PeoplesTrails"):WaitForChild(player.Name)
savedata("...", player.userId, level.Value)
savedata("...", player.userId, coins.Value)
savedata("...", player.userId, gems.Value)
savedata("...", player.userId, wins.Value)
savedata("...", player.userId, xp.Value)
savedata("...", player.userId, xpneeded.Value)
savedata("...", player.userId, rebirths.Value)
savedata("...", player.userId, {r = colornumbers.Value.r, g = colornumbers.Value.g, b = colornumbers.Value.b})
savedata("...", player.userId, trail.Value)
end)
(names of datastores were removed)
All constructive criticism, ideas, and suggestions, are accepted!