I have a script to parent checkpoint triggers to the workspace, and when they are touched(through magnitude), and destroys them. But the trigger isnt destroyed. after some debugging, the script thinks the part is destroyed. Hers the script:
for i,v:BasePart in pairs(chapobj.checkpointtriggers:GetChildren()) do
v.Parent = chapobj.wspacefolder.checkpointtriggers
local connection = nil
connection = RunService.Heartbeat:Connect(function()
print("updating "..tostring(math.floor((v.Position - Character.PrimaryPart.Position).Magnitude)))
if math.floor((v.Position - Character.PrimaryPart.Position).Magnitude) <= 7 then
print("Checkpoint Updated To, "..v.Name)
chapobj.currentcheck.Value = tonumber(v.Name)
updateChecks(chapter,chapobj.currentcheck.Value)
v:Destroy()
connection:Disconnect()
end
end)
end
I’ve had a similar problem like this in other programming languages, and I know how to fix them, although I’m not sure if it works with lua. So try this:
for i,v:BasePart in pairs(chapobj.checkpointtriggers:GetChildren()) do
local v2 = v
v2.Parent = chapobj.wspacefolder.checkpointtriggers
local connection = nil
connection = RunService.Heartbeat:Connect(function()
print("updating "..tostring(math.floor((v2.Position - Character.PrimaryPart.Position).Magnitude)))
if math.floor((v2.Position - Character.PrimaryPart.Position).Magnitude) <= 7 then
print("Checkpoint Updated To, "..v2.Name)
chapobj.currentcheck.Value = tonumber(v2.Name)
updateChecks(chapter,chapobj.currentcheck.Value)
v2:Destroy()
connection:Disconnect()
end
end)
end