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 4 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

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

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

2 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 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:

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()
    local Clonedvc = vc:Clone()
        if attached == true then
            attached = false
        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)
0
now im getting an error that says "MouseButton1Down is not a valid member of Player" Fxding_cam 60 — 4y
0
oh wait hold on. Fxding_cam 60 — 4y
0
I fixed up the script a bit by telling where the cloned model is and it worked! Fxding_cam 60 — 4y
Ad
Log in to vote
1
Answered by
hallmk7 50
4 years ago
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
               vc:Destroy() -- or whatever u wanted detached just destroy that...
            end


        end)

Answer this question