So basically my recent posts are kind of similar, but I’m making an obby, when I touch the checkpoint part which is the part, it says a message in the chat. And when I touch the part a 2nd time it doesn’t pop up, I got that. But I want to know what to do when you leave and join the game back and touch the part you already have touched that it doesn’t show up, I want it to only show up once.
Well, then you could just keep all the checkpoints a player touched in a dictonary (for all players of course) and then just check if that player touched the checkpoint already or not.
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“Stage”)
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)
if success then
player.leaderstats.Stage.Value = data
else
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:SetAsync(player.UserId, player.leaderstats.Stage.Value)
end)
if success then
print("Data Saved")
else
warn(errorMessage)
end
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetChildren()) do
v:Kick(“Server Closed”)
end
Store the values of those BoolValues in a DataStore instance when a player leaves the game and recreate them whenever that player rejoins the game.
local Game = game
local Players = Game:GetService("Players")
local DataStoreService = Game:GetService("DataStoreService")
local CheckpointStore = DataStoreService:GetDataStore("CheckpointStore")
local function OnPlayerAdded(Player)
local Success, Result = pcall(function() return CheckpointStore:GetAsync(Player.UserId) end)
if not Success then warn(Result) return end
if type(Result) ~= "table" then return end
for _, Name in ipairs(Result) do
local BoolValue = Instance.new("BoolValue")
BoolValue.Name = Name
BoolValue.Value = true --Technically not necessary but I'll include it anyway.
BoolValue.Parent = Player
end
end
local function OnPlayerRemoving(Player)
local Data = {}
for _, Child in ipairs(Player:GetChildren()) do
if Child:IsA("BoolValue") then table.insert(Data, Child.Name) end
end
local Success, Result = pcall(function() return CheckpointStore:SetAsync(Player.UserId, Data) end)
if not Success then warn(Result) end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
This is just an example so don’t expect it to work as is, you may need to perform some minor modifications beforehand.