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