Local Spawn Barrier

I am currently working on an obby, and I want a feature where if you touch the next spawnpoint then there will be a local barrier which blocks you off from going back. I have tried putting local scripts inside the barrier but it doesn’t work. Right now this is my code in a server script:

--Variables

barrier = workspace.Stages.Jumps.Barrier

--Commands

script.Parent.Touched:Connect(function(hit)
	barrier.CanCollide = true
end)

Try putting the local script should in StarterPlayerScripts.

Thank you, It does work now and I just added an ‘in pairs loop’ to constantly keep it running.