I'm trying to make something where if an object is touched it will weld that part to the main part. It works but when I run an event from a GUI to delete the weld it comes back as nil with this error code: attempt to index nil with 'Destroy'
Heres the script:
local main = script.Parent
local weld
script.Parent.Touched:Connect(function(plart)
local other = plart --plart was a typo (edit)
local weld = Instance.new("Weld", main)
weld.C0 = main.CFrame:Inverse() * other.CFrame
weld.Part0 = main
weld.Part1 = other
end)
game.ReplicatedStorage.DelWeld.OnServerEvent:Connect(function()
weld:Destroy()
script.Disabled = true
end)
If anyone could help me that would be appreciated.
Thank you.
