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
And prints 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,
Claimed prints twice and the weld duplicates
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!