Utilities 5 min read

Build Per-Player Quests and Interaction Cooldowns

Create a small crystal hunt with personal progress and a reusable gate against rapid repeats.

Record what each player collected

Put three crystals in QuestCrystals. Keep a server table of collected crystal instances keyed by player. A touch should increment progress only the first time that player reaches a given crystal. Leave the crystals visible for teammates. Store a count and a completion flag as attributes for the HUD to read.

Key cooldowns by action

A single global timer can make players block each other. Use an action name along with the player to track separate deadlines. Return the remaining time when a request comes too early so the interface can show feedback. Clear player state on departure if you store players by strong reference.

Test the reward separately

Visit a crystal twice, then finish the quest with two clients in different orders. Keep the completion reward in one server handler and check whether it has already been awarded before changing the player's balance.

Make the objective concrete

Create a flat area with three visibly different crystals and put their parts in QuestCrystals. Put one crystal close to the start, one at the end of a path and one behind a simple obstacle. Define the quest as collecting three different crystals during this visit. A personal quest lets two players touch the same visible object without taking progress from one another. Put a counter near the top of the HUD so players can tell when a touch counts. For the first test, do not add a reward or persistence. It is easier to see whether collection is correct when progress is the only result.

Identify discoveries separately for each visitor

Maintain a table keyed by player, then use an individual crystal as the key in that player's set. On contact, locate the Player from the character that touched the crystal. If that entry already exists for the visitor, leave their count alone. Otherwise, record discovery before increasing the value. Doing it in that order prevents overlapping touches from awarding two points for one object. Keep the visible crystals in Workspace so the others can still see the path. If your design later hides a collected crystal for its owner, display that change on the owner's client while keeping the authoritative record on the server.

if seen[crystal] then
    return
end
seen[crystal] = true
player:SetAttribute("QuestCrystals", (player:GetAttribute("QuestCrystals") or 0) + 1)

Decide what the interface reads

Put the current count and completion flag on the Player. A local HUD can read the starting amount and update when that attribute changes. Read the initial value immediately after connecting the listener, since a player can collect a nearby crystal while the UI initializes. Display a compact message such as 2 of 3 crystals and replace it with a completed label at the end. Use the same threshold on the server that the UI displays. If you decide to support more than one quest, put the objective identifier into your data design rather than reusing a single shared completion flag for unrelated activities.

Add a reusable action cooldown

An interaction such as talking to the quest giver can have a cooldown even though crystals are deduplicated separately. Give that action its own name and let the module track a deadline for the current player. Repeated activations before that deadline should return the remaining delay instead of reopening the dialogue. At the end of the cooldown, allow the next activation and record a new deadline. Try sharing the module between the quest giver and a lobby switch. Verify that using one doesn't delay access to the other. Clear player state on departure whenever it is stored in a table that would otherwise keep a reference to the player.

Verify shared play before attaching a reward

Collect one crystal twice and check that the second touch doesn't move the counter. Have a second client collect the same crystal; its personal counter should still increase. Finish the route with the two players in different orders, then reset one character and inspect the counter. The Player object stays for the visit, so a character reset should preserve that user's progress. If a prize is added, set an award flag as part of granting it and check that flag before paying it again. Test an intentional reconnect separately: the linked quest keeps session progress, so a new visit starts fresh unless you add a persistence design for the objective.

Related scripts