An Ending System that can be Easily Added to

I’m currently working on an “ending system” for a game, where players have to bring multiple items (tools) to a specific spot (part) to complete the ending. Each ending would require 2-3 tools to be brought to the part. I’m able to make it work for each individual ending, but I thought I’d be better off making 1 script that handles all the endings in one place. My only issue is that I’m not too sure what the most efficient way of doing that would be.

My idea for the script is a system that would detect when a player touches a part (a goal) in the “goals” folder, then it would check whether or not they have a tool, and if it’s one of the correct tools for the goal. If the tool is one of the required tools, it would take the tool from the player and check if all other tools have been put into the goal part. If they have, the ending is complete, if not, it waits for the other tools.

I’ve made the system to detect when a player comes into contact with a goal, but now I’m stuck on how I would go about detecting if a player is holding a tool, and whether or not it’s the correct tool. Like I said, I’m trying to do this in one script so that other endings can easily be added without any edits done to the script.

Any ideas to help are greatly appreciated.

Unless you’re making something massive you could keep a function to trigger every ending on a module, keep a list of conditions and play the according ending if every condition is met (Put the endings with higher priority higher on the if statements)

And for checking if the players have a tool i just made a quick function to check, i don’t know if it will work but it is a example of how it could be done

local x=false
local y=false
local z=2

local endingsModule=require()--A module with functions for every ending

local function hasTool(tool)
	for _,player in game:GetService("Players"):GetPlayers() do
		local character=player.Character
		if not character then continue end--Move to next player, this one is dead
		local charTool=character:FindFirstChildOfClass("Tool")
		
		if charTool and charTool.Name==tool.Name then --Someone has the tool equipped
			return true
		end
		
		if player.Backpack:FindFirstChild(tool.Name) then --Someone has the tool on their backpack
			return true
		end
	end
	--Nobody had the tool
	return false
end


if x and y then
	endingsModule.Ending1()
elseif z>1 and x then
	endingsModule.Ending2()
elseif hasTool(Tool1) and hasTool(Tool2) then
	endingsModule.Ending3()
end