How to create a "Treasure hunt" script?

I really want to create a sort of treasure hunt script, so people can find a certain object and use a proximity prompt to sort of “collect” it, i havent really been able to find a script that really works for me so far, ive looked up tutorials for it but all i really get are roblox egg hunt stuff.

ive tried following this tutorial on a seperate experience from my main game, and while it does work its… messy, to say the least, and when i tried to port it to the main experience it didnt work [I didnt do the saving and loading part if it means anything]

im really hoping that someone has any better ideas for a treasure hunt esc script, preferably using a proximity prompt- or atleast a better tutorial to follow so i can make this thing i wanna do work? please and thank you!

1 Like
  1. When a player joins the game check how many of the items they had before they left and if they don’t have data set it to 0. Once you have this data load it onto a numberValue so you can check the value throughout your game.
  2. When a player collects an egg by triggering the proximity prompt you should add 1 to the number of eggs collected and if this value has just reached the max they can get, reward them with something. If they have excessive eggs just don’t do anything.
  3. When a player leaves save their numberValue value to a datastore.

This is a basic quick way to how I think you can achieve this.

I already know these things, but i dont know how to do them, and i dont really need it to save/load, atleast in a traditional sense, since the hunt is just a for fun badge thing in a roleplay game.

I could write some basic code for you if you want. Also, what’re they hunting? Is it specific like different types of eggs or is it number-based like the amount of coins found?

I would definetly appreciate some code i could reference off of. as for the hunt;
There are some dumb looking plushies i made that are scattered across the map (all hidden until you find the very first one, in which all of them become visible), i want it so that you press the proximity prompt it registers that you collected them by turning the plushies eyes yellow instead of destroying it or something

You could do something like this:

--Client script
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

Players.LocalPlayer.CharacterAppearanceLoaded:Wait() --Allows for the game to shortly load

local Tag = "Plushie"
local TaggedInstances = CollectionService:GetTagged(Tag)

local MaxToCollect = #TaggedInstances
local Collected = 0

for _, Plushie:BasePart in TaggedInstances do
	local Prox = Instance.new("ProximityPrompt")
	Prox.HoldDuration = 1
	Prox.Parent = Plushie
	
	local Connection:RBXScriptConnection;
	Connection = Prox.Triggered:Connect(function(playerWhoTriggered: Player)
		Plushie.Color = Color3.new(0, 1, 0)
		
		Collected += 1
		if Collected == MaxToCollect then 
			print("Got all the plushies!")
		end
		
		Connection:Disconnect()
		Prox:Destroy()
	end)
end
1 Like

So after messing around for a while, i made this work! but i cant seem to incorporate the part were the other plushies appear when the starter plushie/first plushie is found, if you could possibly help me with that, id be very thankful, if not, still thank you! because this definitely helped with a majority of my problems :3

You could do something like this:

--Client script
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

Players.LocalPlayer.CharacterAdded:Wait()

local Tag = "Plushie" --Regular plushie tag
local Tag2 = "StarterPlushie" --Starter plushie tag

local TaggedInstances:{BasePart} = CollectionService:GetTagged(Tag)
local StarterPlush:BasePart = CollectionService:GetTagged(Tag2)[1]

local MaxToCollect = #TaggedInstances + 1
local Collected = 0

local function Setup(Plushie:BasePart)
	Plushie.Transparency = 0
	
	local Prox = Instance.new("ProximityPrompt")
	Prox.HoldDuration = 1
	Prox.Parent = Plushie

	local Connection:RBXScriptConnection;
	Connection = Prox.Triggered:Connect(function(playerWhoTriggered: Player)
		Plushie.Color = Color3.new(0, 1, 0)
		
		Collected += 1
		if Collected == MaxToCollect then 
			print("Got all the plushies!")
		end
		
		print(Collected)
		
		if Plushie == StarterPlush then --Other plushies only get setup when the starter plushie is triggered
			for _, X in TaggedInstances do
				Setup(X)
			end
		end
		
		Connection:Disconnect()
		Prox:Destroy()
	end)
end

Setup(StarterPlush)

If you need me to explain anything just ask

1 Like

This doesnt seem to be working for me, which is okay
the other plushies are in replicated storage if you think that may be causing issues? ive been trying to have the script move the folder of plushies to the workspace, Should i just automatically have them in the workspace?

The script assumed that all these plushies were in workspace so that’s why it probably wasn’t working for you. Also, make sure you tag your plushies accordingly

I was in studio so I tested my own script and this is what I got:

–Before activating the starter “plushie”
image

–After activating the starter “plushie”
image

–After activating all the “plushies”
image
image

1 Like

Alrighty i just did some of my own messing around and put the plushies into the workspace, it works now which is absolutely awesome! thank you for all your help you’ve been super cool

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.