yes, I’m completely sure. I can show you my script now.
local function teleportPlayers()
if #list > 0 then
billboard.Frame.Status.Text = "TELEPORTING"
billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
local playersToTeleport = {}
local teleportTime = 0
for i=1,#list do
if game.Players:findFirstChild(list[i]) then
table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
else
table.remove(list,i)
end
end
local code = TS:ReserveServer(placeId)
teleporting = true
TS:TeleportToPrivateServer(placeId,code,playersToTeleport)
repeat wait() until #list <= 0
billboard.Frame.Status.Text = "READY"
billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
teleporting = false
end
local playerID = player.UserId
local data = {
Coins = player.leaderstats.Coins.Value;
XP = player.leaderstats.XP.Value;
Level = player.Level.Value;
Rank = player.Rank.Value;
BlackoutLevel = player.GunLevels.BlackoutLevel.Value;
MP7Level = player.GunLevels.MP7Level.Value;
campaignLevel = player.campaignLevel.Value;
CurrentObjective = player.CurrentObjective.Value;
}
local success, errormessage = pcall(function()
PlayerData:SetAsync(playerID, data)
end)
if success then
print("saved data")
else
print("data didn't save")
warn(errormessage)
end
this is the script I use when the player gets teleported into the place, it saves the data.
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue", leaderstats)
Coins.Name = "Coins"
Coins.Value = 25
local XP = Instance.new("NumberValue", leaderstats)
XP.Name = "XP"
local Level = Instance.new("NumberValue", player)
Level.Name = "Level"
local Rank = Instance.new("NumberValue", player)
Rank.Name = "Rank"
local GunsUnlocked = Instance.new("Folder", player)
GunsUnlocked.Name = "GunsUnlocked"
--add each unlockable gun as a bool value
local GunLevels = Instance.new("Folder", player)
GunLevels.Name = "GunLevels"
local BlackoutLevel = Instance.new("NumberValue", GunLevels)
BlackoutLevel.Name = "BlackoutLevel"
local MP7Level = Instance.new("NumberValue", GunLevels)
MP7Level.Name = "MP7Level"
local campaignLevel = Instance.new("NumberValue", player)
campaignLevel.Name = "campaignLevel"
local CurrentObjective = Instance.new("NumberValue", player)
CurrentObjective.Name = "CurrentObjective"
local playerID = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = PlayerData:GetAsync(playerID)
end)
if success then
Coins.Value = data
XP.Value = data
Level.Value = data
Rank.Value = data
BlackoutLevel.Value = data
campaignLevel.Value = data
CurrentObjective.Value = data
print("loaded data")
end
while true do
local data = {
Coins = player.leaderstats.Coins.Value;
XP = player.leaderstats.XP.Value;
Level = player.Level.Value;
Rank = player.Rank.Value;
BlackoutLevel = player.GunLevels.BlackoutLevel.Value;
MP7Level = player.GunLevels.MP7Level.Value;
campaignLevel = player.campaignLevel.Value;
CurrentObjective = player.CurrentObjective.Value;
}
local success, errormessage = pcall(function()
PlayerData:SetAsync(playerID, data)
end)
if success then
print("saved data")
else
print("data didn't save")
warn(errormessage)
end
wait(60)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerID = player.UserId
local data = {
Coins = player.leaderstats.Coins.Value;
XP = player.leaderstats.XP.Value;
Level = player.Level.Value;
Rank = player.Rank.Value;
BlackoutLevel = player.GunLevels.BlackoutLevel.Value;
MP7Level = player.GunLevels.MP7Level.Value;
campaignLevel = player.campaignLevel.Value;
CurrentObjective = player.CurrentObjective.Value;
}
local success, errormessage = pcall(function()
PlayerData:SetAsync(playerID, data)
end)
if success then
print("saved data")
else
print("data didn't save")
warn(errormessage)
end
end)
this is the script I use when the player joins the game, it loads the data and when the player leaves, it saves it.
local playersInGame = game.ReplicatedStorage.playersInGame
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
wait(0.5)
if playersInGame.Value == 1 then
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue", leaderstats)
Coins.Name = "Coins"
local XP = Instance.new("NumberValue", leaderstats)
XP.Name = "XP"
local Level = Instance.new("NumberValue", player)
Level.Name = "Level"
local Rank = Instance.new("NumberValue", player)
Rank.Name = "Rank"
local GunsUnlocked = Instance.new("Folder", player)
GunsUnlocked.Name = "GunsUnlocked"
--add each unlockable gun as a bool value
local GunLevels = Instance.new("Folder", player)
GunLevels.Name = "GunLevels"
local BlackoutLevel = Instance.new("NumberValue", GunLevels)
BlackoutLevel.Name = "BlackoutLevel"
local MP7Level = Instance.new("NumberValue", GunLevels)
MP7Level.Name = "MP7Level"
local campaignLevel = Instance.new("NumberValue", player)
campaignLevel.Name = "campaignLevel"
local CurrentObjective = Instance.new("NumberValue", player)
CurrentObjective.Name = "CurrentObjective"
local playerID = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = PlayerData:GetAsync(playerID)
end)
if success then
Coins.Value = data
XP.Value = data
Level.Value = data
Rank.Value = data
BlackoutLevel.Value = data
campaignLevel.Value = data
CurrentObjective.Value = data
print("loaded data")
end
wait(0.5)
elseif playersInGame > 1 then
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue", leaderstats)
Coins.Name = "Coins"
local XP = Instance.new("NumberValue", leaderstats)
XP.Name = "XP"
local Level = Instance.new("NumberValue", player)
Level.Name = "Level"
local Rank = Instance.new("NumberValue", player)
Rank.Name = "Rank"
local GunsUnlocked = Instance.new("Folder", player)
GunsUnlocked.Name = "GunsUnlocked"
local GunLevels = Instance.new("Folder", player)
GunLevels.Name = "GunLevels"
local BlackoutLevel = Instance.new("NumberValue", GunLevels)
BlackoutLevel.Name = "BlackoutLevel"
local MP7Level = Instance.new("NumberValue", GunLevels)
MP7Level.Name = "MP7Level"
local playerID = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = PlayerData:GetAsync(playerID)
end)
if success then
Coins.Value = data
XP.Value = data
Level.Value = data
BlackoutLevel.Value = data
print("loaded multiplayer data")
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if playersInGame.Value == 1 then
local playerID = player.UserId
local data = {
Coins = player.leaderstats.Coins.Value;
XP = player.leaderstats.XP.Value;
Level = player.Level.Value;
Rank = player.Rank.Value;
BlackoutLevel = player.GunLevels.BlackoutLevel.Value;
MP7Level = player.GunLevels.MP7Level.Value;
campaignLevel = player.campaignLevel.Value;
CurrentObjective = player.CurrentObjective.Value;
}
local success, errormessage = pcall(function()
PlayerData:SetAsync(playerID, data)
end)
if success then
print("saved data")
else
print("data didn't save")
warn(errormessage)
end
elseif playersInGame > 1 then
local playerID = player.UserId
local data = {
Coins = player.leaderstats.Coins.Value;
XP = player.leaderstats.XP.Value;
Level = player.Level.Value;
Rank = player.Rank.Value;
BlackoutLevel = player.GunLevels.BlackoutLevel.Value;
MP7Level = player.GunLevels.MP7Level.Value;
}
local success, errormessage = pcall(function()
PlayerData:SetAsync(playerID, data)
end)
if success then
print("saved multiplayer data")
else
print("multiplayer data didn't save")
warn(errormessage)
end
end
end)
this is the script I use in the other place, which gets the datastore, loads the data, and also saves it if the player leaves.