Trigger system runs the wrong script

Hello! I am trying to create a simple trigger system. It’s going pretty smoothly, but there’s only one issue that I know of.

For some reason, the script only runs one script. I have set up my trigger script with CollectionService, which is really useful for me. I’ve gotten around making several different tags for different trigger functions by adding a StringValue inside of the trigger part. This is the name of a script. The script reads this StringValue, then runs FindFirstChild over a specific folder in Workspace, where I keep my trigger scripts. The scripts that the trigger will run have a BoolValue named “On”. This goes pretty smoothly, and I’ve set up the scripts to run only if their bool was changed to True.

Now, this system works very well. I’ve tested out one trigger. I decide to test it even more with a new trigger that runs a different script. However, the trigger runs the script that the first trigger should run. I would just abandon CollectionService for this one case, but if I want to add revisions to my trigger script, I’d have to update all of them which would be a hassle.

Here is the first script: the script that controls the trigger.

function debounce(func)
    local isRunning = false    -- Create a local debounce variable
    return function(...)       -- Return a new function
        if not isRunning then
            isRunning = true
 
            func(...)          -- Call it with the original arguments
 
            isRunning = false
        end
    end
end

CanFire = false

local CollectionService = game:GetService("CollectionService")

local Tag = CollectionService:GetTagged("Trigger")

for _, Tag in pairs(Tag) do
	ScriptPlayer = Tag.ScriptToPlay.Value
local function PlayerTouched(Part)
	local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
			local SCRP = game.Workspace.SCRIPTS.TRIGS:FindFirstChild(ScriptPlayer)
			local ONVALUE = SCRP:FindFirstChild("On")
			CanFireStuff()
			CanFire = true
			if CanFire == true then
				ONVALUE.Value = true
				end
			
	end
end

	Tag.Touched:connect(debounce(PlayerTouched)
		
	)
end

function CanFireStuff()
	wait(0.3)
	CanFire = false
end


Here is the second script: the one that is run by the first trigger I’ve placed. It is named GiveMoney. I have not coded this yet.

function debounce(func)
    local isRunning = false    -- Create a local debounce variable
    return function(...)       -- Return a new function
        if not isRunning then
            isRunning = true
 
            func(...)          -- Call it with the original arguments
 
            isRunning = false
        end
    end
end


script.On:GetPropertyChangedSignal("Value"):connect(debounce(function()
	if script.On.Value == true then
	print("moner")
		script.On.Value = false
		end
end))

The third script is literally the same thing, but changed to print “test”.

I still have to get rid of unnecessary debounces, so if that’s the case I’ll let you guys know.

Thank you for reading!

After quite a bit of testing, I fixed it by putting “ScriptPlayer” under

 if game.Players:GetPlayerFromCharacter(Parent) then

Thank you if you wanted to help!