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
01 | button = script.Parent.Parent.Parent |
02 | local vc = game.ReplicatedStorage [ "Rig BP" ] |
03 | local plr = script.Parent.Parent.Parent |
04 | local char = plr.character or plr.CharacterAdded:Wait() |
05 | local attached = true |
06 |
07 | button.MouseButton 1 Down:Connect( function () |
08 | if attached = = true then |
09 | attached = false |
10 | local Clonedvc = vc:Clone() |
11 | Clonedvc.Parent = char |
12 | Clonedvc:SetPrimaryPartCFrame(char:WaitForChild( "UpperTorso" ).CFrame) |
13 |
14 | Clonedvc:SetPrimaryPartCFrame(Clonedvc:GetPrimaryPartCFrame() * CFrame.new( 0 ,-. 84 ,. 02 ) * CFrame.Angles( 6.28 , 3.14 , 0 )) |
15 | local Weld = Instance.new( "WeldConstraint" ) |
look at line 22
This is a scope issue. A scope is a defined region where the program can recognize and use variables and functions declared within it. If an attempt is made to reference these things outside of its respective scope, you'll get an unknown global
exception—meaning it isn't valid in that space but where it was declared. To solve this issue, place the Clonedvc
declaration at a higher space within the .MouseButton1Down
signal:
01 | button = script.Parent.Parent.Parent |
02 | local vc = game.ReplicatedStorage [ "Rig BP" ] |
03 | local plr = script.Parent.Parent.Parent |
04 | local char = plr.character or plr.CharacterAdded:Wait() |
05 | local attached = true |
06 |
07 | button.MouseButton 1 Down:Connect( function () |
08 | local Clonedvc = vc:Clone() |
09 | if attached = = true then |
10 | attached = false |
11 | Clonedvc.Parent = char |
12 | Clonedvc:SetPrimaryPartCFrame(char:WaitForChild( "UpperTorso" ).CFrame) |
13 |
14 | Clonedvc:SetPrimaryPartCFrame(Clonedvc:GetPrimaryPartCFrame() * CFrame.new( 0 ,-. 84 ,. 02 ) * CFrame.Angles( 6.28 , 3.14 , 0 )) |
15 | local Weld = Instance.new( "WeldConstraint" ) |
01 | button = script.Parent.Parent.Parent |
02 | local vc = game.ReplicatedStorage [ "Rig BP" ] |
03 | local plr = script.Parent.Parent.Parent |
04 | local char = plr.character or plr.CharacterAdded:Wait() |
05 | local attached = true |
06 |
07 | button.MouseButton 1 Down:Connect( function () |
08 | if attached = = true then |
09 | attached = false |
10 | local Clonedvc = vc:Clone() |
11 | Clonedvc.Parent = char |
12 | Clonedvc:SetPrimaryPartCFrame(char:WaitForChild( "UpperTorso" ).CFrame) |
13 |
14 | Clonedvc:SetPrimaryPartCFrame(Clonedvc:GetPrimaryPartCFrame() * CFrame.new( 0 ,-. 84 ,. 02 ) * CFrame.Angles( 6.28 , 3.14 , 0 )) |
15 | local Weld = Instance.new( "WeldConstraint" ) |