Make the player speak if they are the first to discover something!

I’m making a story game on Roblox and I ran into a small problem. One of the players has to be the first to discover a secret item and when they find it then make them say that they found it. But the problem is that the game doesn’t know which player found the item so it just picks any random player who did not find the item. For example it’s like finding a dead body or secret door and alerting the other players, or in this case a purple box.

Here is the test place that you can edit in studio if you want to try fixing my problem. Just make sure to send me back an uncopylocked place of your fixed version.
https://www.roblox.com/games/7510438503/Who-found-the-purple-box

Also you can keep and use all the assets in the test place if you wanna use them to make your own game. Thanks if you can help solve this problem!

1 Like

You could use a remote event. So, when a player touches or clicks the purple box, the server would recognise it. Anyways, if I manage to solve this problem by using your uncopylocked game, am I allowed to publish it as my own?

Yes you are allowed to grab all the assets within it and use them, just please try and help me out.

Ok. No problem. I will try to get it as soon as possible.

1 Like

If you can get to fixing my problem soon then that’ll be great, I’m counting on you to make this work.

I’ll try to get it done by the end of this week. (In 7 days) if that’s ok with you. I’m still not 100% sure that it will work out. But I’ll try.

Alright thanks, if you end up fixing it sooner then just let me know and send me back a download file of your working place.

local function challenge_1()
	
	getRandomPlayer()
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Who can find the purple box first?")
	wait(4)
	local purple = game.ReplicatedStorage.PurpleBox:Clone()
	purple.Parent = game.Workspace
	
	repeat wait() until game.Workspace:FindFirstChild("PurpleBox") == nil
	
	getRandomPlayer()
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"I found the box! But wait anyone can say that they found it. How do I make the game know who actually discovered it first? Whoever collects the purple box should be the one to say that they found it. But I can't think of a good way to do that...")
	
	local player = game.Players:GetPlayerByUserId(randomPlayerId)
	local chat = game:GetService("Chat")
	chat:Chat(player.Character or player.CharacterAdded:Wait(), "I found the purple box!")
	wait(60)
end

This should work for you.

purple box.rbxl (41.9 KB)

The player has to use the green box to say that they found it.

First of all, i have a question.
Do you know OOP?
If you do, try making a module for quest creating and store those quests in an array, so like you won’t need to add it manually, if you get my idea.
And all your quest will need tags, many devs are using this technique in their games.
It will help you organize the story game.
And add the status of a quest, has it been finished or not.
And all you have left to do is make a script which will interpretate those tags and execute their statements.

Something went wrong, the game still picks the wrong player for some reason. I tested it with 2 accounts.

Ok so what you’re currently doing is creating and parenting the purple box to workspace. You then have another script inside the purple box that simply “deletes” its when touched. A simple solution is to first delete the script inside the purple box. Then simply create the touch connection when you clone the box:

Basically just replace your function with this one:

local function challenge_1()
	
	getRandomPlayer()
	CreateDialogueEvent:FireAllClients(getPlayerImage(randomPlayerId),"Who can find the purple box first?")
	wait(4)
	local purple = game.ReplicatedStorage.PurpleBox:Clone()
	purple.Parent = game.Workspace
	
	-- Edit here --
	local PlayerWhoFoundPurpleBox = nil; -- This is the player who found the box
	purple.Touched:Connect(function(hit) -- Create the touch function here!
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent); -- Find the player
		if Player then -- Check the player exist
			PlayerWhoFoundPurpleBox = Player; -- Update variable so its the player who found the box
			purple:Destroy() -- destroy disconnects the connection so no need to call :Disconnect()
		end
	end)
	
	-- End of Edit --
	repeat wait() until game.Workspace:FindFirstChild("PurpleBox") == nil -- You could remove this entirely and just move the below code inside the touch function
	CreateDialogueEvent:FireAllClients(getPlayerImage(PlayerWhoFoundPurpleBox.UserId), PlayerWhoFoundPurpleBox.Name.." has found the purple box!!");
	wait(60)
end

Also I left a little note but you could remove the:

repeat wait() until game.Workspace:FindFirstChild("PurpleBox") == nil -- You could remove this entirely and just move the below code inside the touch function

And just add the dialogueEvent inside the touch connection if you want but I left it as is just incase theres another reason the box might get deleted??

3 Likes

Your code appears to be working, I ran multiple tests and added different boxes to find and each of them worked. I will add this to the game and if it works correctly I’ll mark your advice as the solution and I will share an open source demo for everyone to use.

1 Like