Touch with ChatMessage Bug (Solved)

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.
image

LocalScript in StarterPlayerScripts:

Script in the part to touch:

You would need to use DataStoreService to do that. You would need to save the checkpoints they have touched.
Here is a link: DataStoreService | Roblox Creator Documentation

I have a datastore of that checkpoints, I’m only trying to fix chat yes

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.

I actually don’t know what you mean, I’m new to scripting so like

Okay, so you said you have a DataStore set up, how would your saved data look like if I touched the 2nd checkpoint.

uh idk

Blockquotegedsrgryheryertdrtrhuydsrdtjtg

You are using:

local DataStoreService = game:GetService("DataStoreService")
local YourDataStoreName = DataStoreService:GetDataStore("YourDataStoreName")
-- blah blah blah
YourDataStoreName:SetAsync(key, data)

what is your “data” variable in the SetAsync?

Yes I’m using

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

wait(2)

end)

When you get the data, you can set the value in the script and use the FireAllClients in the data script. Like:

local playerStages = {}
-- ...
-- In playerAdded:
playerStages[player.UserId] = data or 1 -- 1 is the starting stage

you can use the thing above for getting it initally and then whenever a player gets a new chckpoint

local playerStages = {}
-- ...
playerStages[player.UserId] += 1

Sorry if you’re annoyed, I don’t know what you mean

Do you have Discord by any chance? So we can just go into a call and I can explain it to you directly?

Yes I actually do its PlasaYara#9182

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.