Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what does Unknown global 'Clonedvc' mean?

Asked by 5 years ago

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

01button = script.Parent.Parent.Parent
02local vc = game.ReplicatedStorage["Rig BP"]
03local plr = script.Parent.Parent.Parent
04local char = plr.character or plr.CharacterAdded:Wait()
05local attached = true
06 
07button.MouseButton1Down: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")
View all 26 lines...

look at line 22

0
i think if u want to destroyit why are u parenting it to replicated storage hallmk7 50 — 5y
0
the problem is after i put "elseif" the script doesn't recognize "clonedvc" Fxding_cam 60 — 5y
0
Clonedvc:Destroy(), script still doesn't recognize "Clonedvc" Fxding_cam 60 — 5y

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

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:

01button = script.Parent.Parent.Parent
02local vc = game.ReplicatedStorage["Rig BP"]
03local plr = script.Parent.Parent.Parent
04local char = plr.character or plr.CharacterAdded:Wait()
05local attached = true
06 
07button.MouseButton1Down: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")
View all 26 lines...
0
now im getting an error that says "MouseButton1Down is not a valid member of Player" Fxding_cam 60 — 5y
0
oh wait hold on. Fxding_cam 60 — 5y
0
I fixed up the script a bit by telling where the cloned model is and it worked! Fxding_cam 60 — 5y
Ad
Log in to vote
1
Answered by
hallmk7 50
5 years ago
01button = script.Parent.Parent.Parent
02local vc = game.ReplicatedStorage["Rig BP"]
03local plr = script.Parent.Parent.Parent
04local char = plr.character or plr.CharacterAdded:Wait()
05local attached = true
06 
07button.MouseButton1Down: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")
View all 26 lines...

Answer this question