How would I detect a player who left the game and rejoined to see if they clicked a proximity prompt

So I’ve been working on a game for a week or two now and I’m wondering if there is a way to detect if a player clicked the proximity prompt from when the last time they joined the game, because the proximity prompt gives you cash and I want to disable it so you can’t just rejoin and get infinite cash

If there is any topics on this or if there is a way to detect this tell me, please

You can save if the player has clicked the prompt in a datastore.

could you show me a example of what you mean?

You can save if the player has clicked the prompt in a datastore.

Yes, you can absolutely save in a Roblox DataStore if a player has clicked a prompt

.

Here’s how you can approach it:

  1. Enable DataStores in Studio: First, you need to ensure DataStores are enabled for your game in Roblox Studio. You can do this by going to File > Game Settings > Security and enabling “Enable Studio Access to API Services”.
  2. Create a DataStore: You’ll need to create a DataStore to store the information. Use DataStoreService:GetDataStore() to access or create your DataStore, giving it a unique name (e.g., “PlayerPromptClicks”).
  3. Identify the Player: When a player clicks the prompt, you need to identify them. The player’s unique UserId is the standard way to do this.
  4. Save the Data:
  • Create a data structure (like a Lua table) to hold the information you want to save. For example, a simple boolean value (true/false) could indicate whether the player clicked the prompt.
  • Use SetAsync() to save this data to the DataStore, using the player’s UserId as the key and your data structure as the value.
  • It’s recommended to wrap your SetAsync() call in a pcall() function to handle potential errors during the save process.
  1. Load the Data:
  • When the player joins the game, use GetAsync() to retrieve their saved data from the DataStore, using their UserId as the key.
  • Again, use a pcall() to handle potential errors during loading.
  • If the data loads successfully, you can then check if the player has previously clicked the prompt and adjust the game accordingly (e.g., don’t show the prompt again).

Important Considerations:

  • Error Handling: Always wrap your DataStore calls in pcall() to gracefully handle network issues or DataStore failures.
  • Data Structure: Decide on a data structure that suits your needs. A table is often used to store multiple data points for a player.
  • DataStore Limits: Be mindful of DataStore limits (e.g., key/value size, read/write requests per minute).
  • Saving Frequency: Determine when to save the data. A common approach is to save when the player leaves, when the server shuts down, and perhaps periodically with an auto-save loop.
  • Loading: Load the player’s data when they join the game so that you can access it in memory and avoid frequent DataStore requests.

If u only have the boolean to save then u can do
local dataStore = DataStoreService:GetDataStore(“datastorenamehere”)
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, data) – this is the true or false
end

then use getasync to get the value when the player joins.

What a quick and well formatted response!

1 Like

I’m not the best scripter it may just be me but its still not working local "prox = script.Parent.ProximityPrompt
local PromptTriggerd = false

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.ProximityPrompt.Enabled = true
game.ReplicatedStorage.Dialouge:FireClient(player)
PromptTriggerd = true
end)

local DataStoreService = game:GetService(“DataStoreService”)
local PlayerPrompt = DataStoreService:GetDataStore(“PlayerPromptClicks”)

if PromptTriggerd == true then
prox.Enabled = false
end

game.Players.PlayerAdded:Connect(function(player)

	local success, playerPrompt = pcall(function()
		PlayerPrompt:SetAsync(player.UserId)
	end)

	local success, playerPrompt = pcall(function()
		return PlayerPrompt:GetAsync(player.UserId)
	end)
end)"

u have to set the value when doing setasync and getasync like this: setasync(id, data)
the first parameter (id) is the “name” of the entry and the second is the value of the entry.

I still don’t understand what this is supposed to mean I am sorry I am not the best scripter

read the link i sent on my first post, it has a detailed guide on how to set everything up.

So here’s the new script "local prox = script.Parent.ProximityPrompt
local PromptTriggerd = false

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
script.Parent.ProximityPrompt.Enabled = true
game.ReplicatedStorage.Dialouge:FireClient(player)
PromptTriggerd = true
end)

local DataStore = game:GetService(“DataStoreService”)

game.Players.PlayerAdded:Connect(function(player)
local data
local success, err = pcall(function()

	data = DataStore:GetAsync(player.UserId)

end)

while true do
wait()
if success and data then

		prox.Enabled = false
	end
end

end)"

I used “while true do” to always check instead of else but it still does not work and when I use else it says “No player data” because the else is (“No player data”)

A few things here, first right now the variable you are using is server side and so if one player triggers it then it triggers for all players, so u need to have a copy of each player’s value to use. Second you are not setting the value when the proximity prompt is triggered. You should use setasync there to save the values.

Won’t the “player.userID” fix the first thing you said? also how do I set the value when it is triggered do I use prox.triggered:connect(function()
end)