I need help converting this script from working from a clickdetector into a gui button
at the momment the script below works from a clickdectecter inside a brick but I want it to work from a button in a gui
weld = false
welded = false
function touch(part)
if part:IsA ("BasePart") then
if weld == true then
if welded == false then
w = Instance.new("Weld")
w.Part0,w.Part1 = script.Parent.Platform,part
w.C0 = part.CFrame:toObjectSpace(script.Parent.Platform.CFrame):inverse()
w.Parent = script.Parent.Platform
welded = true
end
end
end
end
function bttnClick()
if weld == true then
if welded == true then
w:remove()
end
weld = false
welded = false
elseif weld == false then
weld = true
end
end
function childRemove(child)
if child.ClassName == "Weld" then
bttnClick()
end
end
script.Parent.Platform.Touched:connect(touch)
script.Parent.Weld1.ClickDetector.MouseClick:connect(bttnClick)
script.Parent.Platform.ChildRemoved:connect(childRemove)