Weld duplicates when parenting an object to Workspace

Hello!

So basically I am doing a basic Orb that welds to your character when you touch it.
This works fine, the orb looks like this when you touch it image
And prints image once.

The problem begun when I created a system where there is a countdown for “The game to start” and once it gets to 0, the orb comes from the Lighting and parents to the Workspace, so you can “Play”

Part of the script that causes the problem
--//Userdata

part = script.Parent
gameStatus = game.Workspace.GameBeginsScript.Status
lighting = game.Lighting

part.Parent = lighting

gameStatus.Changed:Connect(function(property)
	if gameStatus.Value == "Game started, pick the orb and protect it!" then
		print("The game has started, placing the orb in the Workspace")
		part.Parent = game.Workspace
	end
end)
"Here is the touched Event part of the script which works fine without the gameStatus part
--//Variables
debounce = true
Claimed = false

--//Touched the orb
part.Touched:Connect(function(hit)	
		 local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and debounce == true and Claimed ==false then
			Claimed = true				
			print("Claimed")
			
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)							
			local humanoidRoot = hit.Parent.HumanoidRootPart
			local weld = Instance.new("Weld")
			
			part.CFrame = humanoidRoot.CFrame * CFrame.new(0,6,0)	
			part.BrickColor = BrickColor.new("Teal")	
			part.Anchored = false

			weld.Part0 = humanoidRoot -- Thing we are welding to (Part 0)
			weld.C0 = humanoidRoot.CFrame:inverse() -- When player twists the object will twist too relative to player
			weld.Part1 = part -- Part 1 is the part we are welding, part in this case
			weld.C1 = part.CFrame:inverse() 
			weld.Parent = part
						
			wait(2)
			
			debounce = true

           while Claimed == true do
				player.leaderstats.Points.Value = player.leaderstats.Points.Value +1
				wait(1)	
			end
								
	end
end)

When the changed event fires because the countdown gets to 0 and I touch the orb, image
Claimed prints twice and the weld duplicates image

It always happens twice when the event is working

Bug reproduction

Any help with this I would appreciate it a lot, if you have any questions please let me know!

Add a debounce = false after the if debounce == true line. The problem was that the debounce was always true and also add Claimed = false after the while Claimed == true do

1 Like

The debounce makes sense, thank you, but it did not fix it

Claimed = false after the while Claimed == true do just stops the loop just when it started so it is not giving points when you have the orb claimed (Or in case you meant after the entire loop, it did not work either)

But, I did notice, in the video I uploaded, I am receiving 2 points every second when it should be 1, maybe has something to do with the overall problem? This happens when the changed event is working

The bug only happens when I parent the orb to the lighting and then bring it back with the Changed event

After doing some testing, determined that this bug only happens when I parent the Orb to the lighting and then bring it back to the workspace, that specific process is what causes the duplication.

If someone can give me a hand to understand I would appreciate it a lot