I want to make a script where when a player first joins my game, they get teleported to another game that has the tutorial. If the player has played the game before and has completed the tutorial, they won’t be teleported to the tutorial place.
I already know how to make a teleport script between different games, I’m just wondering if there is a way to detect if the player has completed the tutorial before playing the game.
Datastores, when they join check if they have or not, if they have not send em to the tutorial place.
If they complete said tutorial then change a value in said datastore to true that way you know next time they have completed the tutorial
Alright, now I have two scripts. For some reason the remote event in the datastore script isnt calling.
Server Script:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local database = DataStoreService:GetDataStore("data")
local sessionData = {}
function PlayerAdded(player)
local success = nil
local playerData = nil
local attempt = 1
local teleport = game.ReplicatedStorage:WaitForChild("TutorialTeleport")
repeat
success, playerData = pcall(function()
return database:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait(3)
end
until success or attempt ==5
if success then
print("Connected to database")
if not playerData then
print("Assigning default data")
playerData = {
["HasNotPlayed"] = {"StartingTutorial"}
}
print("Player is teleporting")
teleport:FireClient(player)
end
sessionData[player.UserId] = playerData
else
warn("Unable to get data for", player.UserId)
player:Kick("Unable to load your data. Try again later!")
end
end
Players.PlayerAdded:Connect(PlayerAdded)
function PlayerLeaving(player)
print(player, "is leaving")
if sessionData[player.UserId] then
local success = nil
local errorMsg = nil
local attempt = 1
repeat
success, errorMsg = pcall(function()
database:SetAsync(player.UserId, sessionData[player.UserId])
end)
attempt += 1
if not success then
warn(errorMsg)
task.wait(3)
end
until success or attempt ==5
if success then
print("Data saved for", player.Name)
else
warn("Unable to save for", player.Name)
end
end
end
Players.PlayerRemoving:Connect(PlayerLeaving)
function ServerShutdown()
function ServerShutdown()
print("Server Shutting Down")
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(function()
PlayerLeaving(player)
end)
end
end
end
game:BindToClose(ServerShutdown)
Local script:
local teleport = game.ReplicatedStorage:WaitForChild("TutorialTeleport")
local teleportservice = game:GetService("TeleportService")
local placeId = 5223259574
local player = game.Players.LocalPlayer
teleport.OnClientEvent:Connect(function(player)
teleportservice:TeleportAsync(placeId,{player})
end)