LocalScript in Starterplayerscript not working 1 times on 2

Hello devs :grin:!

So i have this script for a checkpoint system however. Sometimes I play and it detect the player touch sometimes not with no errors and I can’t understand why this is really weird..

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local ts = game:GetService("TweenService")

local currentSpawn = nil

local function onCharacterAdded(char)
	if currentSpawn then
		char:WaitForChild("HumanoidRootPart").CFrame = currentSpawn.CFrame + Vector3.new(3, 3, 0)
	end
end


local flagsFolder = workspace:WaitForChild("Checkpoints")

local function FlagAnimation(flagPart)
	local beams = flagPart.Parent.Beam
	local flagUnion = flagPart.Parent.Union
	local FlagRotation = flagUnion.CFrame
	print(FlagRotation)
	beams.Beam1.Transparency = NumberSequence.new(1)
	beams.Beam2.Transparency = NumberSequence.new(1)
	print(flagPart)
	flagPart.Parent.ParticlesPart.ParticleEmitter.Enabled = true
	game.SoundService.Gameplay.Checkpoint:Play()
	game.SoundService.Gameplay.Checkpoint2:Play()

	local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Elastic, Enum.EasingDirection.Out)
	
	flagUnion.CFrame = flagUnion.CFrame * CFrame.Angles(math.rad(30), 0, 0)
	local goal = {CFrame = FlagRotation}
	local tween = ts:Create(flagUnion, tweenInfo, goal)
	tween:Play()
	task.wait(0.35)

	flagPart.Parent.ParticlesPart.ParticleEmitter.Enabled = false
	task.wait(0.2)
	game.SoundService.Gameplay.Checkpoint:Stop()
end

player.CharacterAdded:Connect(onCharacterAdded)

for _, flag in pairs(flagsFolder:GetChildren()) do
	if flag:IsA("Model") then
		print("yeah model")
		local collidePart = flag:FindFirstChild("Collision")
		if collidePart and collidePart:IsA("BasePart") then
			print("yes")
			collidePart.Touched:Connect(function(hit)
				print("touched")
				local touchingChar = hit:FindFirstAncestorOfClass("Model")
				if touchingChar and touchingChar == player.Character then
					print(" touching char")
					-- Check if this is a new flag (not current)
					if collidePart ~= currentSpawn then
						print(" currentspawn")
						currentSpawn = collidePart
						print("Touched new flag:", collidePart:GetFullName())
						
						FlagAnimation(collidePart)


					end
				end
			end)
		end
	end
end

If anyone has an idea why it might not be working that’d help a lot thanks ^^!