so i made a button gui when you would press it a model would attach on the player now i want the script to delete the item when the button gui is pressed again but i get this "blue underline" that says unknown global 'clonedvc'
here is the script
button = script.Parent.Parent.Parent
local vc = game.ReplicatedStorage["Rig BP"]
local plr = script.Parent.Parent.Parent
local char = plr.character or plr.CharacterAdded:Wait()
local attached = true
button.MouseButton1Down:Connect(function()
if attached == true then
attached = false
local Clonedvc = vc:Clone()
Clonedvc.Parent = char
Clonedvc:SetPrimaryPartCFrame(char:WaitForChild("UpperTorso").CFrame)
Clonedvc:SetPrimaryPartCFrame(Clonedvc:GetPrimaryPartCFrame() * CFrame.new(0,-.84,.02) * CFrame.Angles(6.28,3.14,0))
local Weld = Instance.new("WeldConstraint")
Weld.Part0 = Clonedvc.Main
Weld.Part1 = char:WaitForChild("UpperTorso")
Weld.Parent = char:WaitForChild("UpperTorso")
print("Player is wearing model")
elseif attached == false then
attached = true
Clonedvc.Parent = game.ReplicatedStorage
end
end)
look at line 22

3 comments
i think if u want to destroyit why are u parenting it to replicated storage
the problem is after i put "elseif" the script doesn't recognize "clonedvc"
Clonedvc:Destroy(), script still doesn't recognize "Clonedvc"