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

Why does my script say this? attempt to index nil with 'Name'

Asked by 4 years ago
Edited 4 years ago

Hello. I hope this should be a quick fix. Here is my localscript:

local LegionFrame = script.Parent.Parent.Legions
 local UniformFrame = script.Parent.Parent.Uniforms
 local MorphsDir = game.ReplicatedStorage.Morphs
 local Libs =game.ReplicatedStorage.Libs
 local RemoteEvent = game.ReplicatedStorage.Youneedthis
 local Player = game.Players.LocalPlayer




for i,v3 in pairs(MorphsDir:GetChildren()) do
    local Button = Instance.new("TextButton")
    Button.Size = UDim2.new(1,0,0,50)
    Button.BackgroundTransparency = 1
    Button.Font = "SciFi"
    Button.TextSize = 30
    Button.TextXAlignment = "Left"
    Button.TextColor3 = Color3.fromRGB(255,255,255)

    Button.Text = v3.name
    Button.Parent = LegionFrame

    Button.MouseButton1Click:Connect(function()
         for i,v2 in pairs(UniformFrame:GetChildren()) do
            if v2.ClassName == "TextButton" then
                v2:Destroy()
            end
         end
         for i,Morph in pairs(v3:GetChildren()) do 
            local Button2 = Instance.new("TextButton")
            Button2.Size = UDim2.new(1,0,0,50)
            Button2.BackgroundTransparency = 1
            Button2.Font = "SciFi"
            Button2.TextSize = 30
            Button2.TextXAlignment = "Left"
            Button2.TextColor3 = Color3.fromRGB(255,255,255)

            Button2.Text = Morph.Name
            Button2.Parent = UniformFrame

            Button2.MouseButton1Click:connect (function()
                print(Button2.Text)
                RemoteEvent:FireServer(Morph, Button)
            end)
        end 
    end)        
end

Here is the script:

-- This is just a part of the script the other things are unimportant.
game.ReplicatedStorage.Youneedthis.OnServerEvent:Connect(function(Player, Morph, Button)
    coroutine.resume(coroutine.create(function()
    if Player.Character:FindFirstChild(Morph.Name) == nil then
        wait(0.1)
        local FindMorph = game.ReplicatedStorage.Morphs:FindFirstChild(Morph.Name)
        local Cloned = FindMorph:FindFirstChild(Button.Name):Clone() -- Error here
        Cloned.Parent = Player.Character
        for i, v in pairs(Cloned:GetChildren()) do
            coroutine.resume(coroutine.create(function()
            if v:IsA("BasePart") then
                if v.Name ~= "Middle" then
                    local w = Instance.new("Weld")
                    w.Part0 = Cloned["Middle"]
                    w.Part1 = v
                    w.C0 = w.Part0.CFrame:inverse() * CFrame.new(w.Part1.Position)
                    w.C1 = w.Part1.CFrame:inverse() * CFrame.new(w.Part1.Position)
                    w.Parent = w.Part0
                else
                    coroutine.resume(coroutine.create(function()
                        wait(0.1)
                    local w = Instance.new("Weld", Player.Character["Torso"])
                    w.Part0 = Player.Character["Torso"]
                    w.Part1 = v
                    w.C0 = CFrame.new(0, 0, 0)
                    end))
                end
            end
            end))
        end
0
What line? Leamir 3138 — 4y
0
I made a comment on the line that the error is on its in the normal script. peter21340 41 — 4y
0
The problem is you're passing a TextButton you created in a LocalScript, in FireServer. The server cannot see stuff you create from LocalScripts so it sees nil Amiaa16 3227 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I found a fix myself by adding:

RemoteEvent:FireServer(Morph, Button, Button2)

It says no errors, but I found out the morph script isn't working.

game.ReplicatedStorage.Youneedthis.OnServerEvent:Connect(function(Player, Morph, Button, Button2)
    coroutine.resume(coroutine.create(function()
    if Player.Character:FindFirstChild(Morph.Name) == nil then
        wait(0.1)
        local FindMorph = game.ReplicatedStorage:FindFirstChild(Button.Name)
        local Cloned = FindMorph:FindFirstChild(Button2.Name)
        local Cloned2 = Cloned:GetChildren()
        Cloned.Parent = Player.Character
        for i, v in pairs(Cloned:GetChildren()) do
            coroutine.resume(coroutine.create(function()
            if v:IsA("BasePart") then
                if v.Name ~= "Middle" then
                    local w = Instance.new("Weld")
                    w.Part0 = Cloned["Middle"]
                    w.Part1 = v
                    w.C0 = w.Part0.CFrame:inverse() * CFrame.new(w.Part1.Position)
                    w.C1 = w.Part1.CFrame:inverse() * CFrame.new(w.Part1.Position)
                    w.Parent = w.Part0
                else
                    coroutine.resume(coroutine.create(function()
                        wait(0.1)
                        local w = Instance.new("Weld", Player.Character["Torso"])
                        w.Part0 = Player.Character["Torso"]
                        w.Part1 = v
                        w.C0 = CFrame.new(0, 0, 0)
                    end))
                end
            end
            end))
        end
        for i, v in pairs(Cloned:GetChildren()) do
            coroutine.resume(coroutine.create(function()
            if v:IsA("BasePart") then
                v.Anchored = false
                v.CanCollide = false
            end
            end))
        end
        if Player.Character:findFirstChild("Shirt") ~= nil then
            Player.Character["Shirt"]:remove()
        end
        if Cloned2:findFirstChild("Shirt") ~= nil then
            Cloned:FindFirstChild("Shirt"):Clone().Parent = Player.Character
        end
        if Player.Character:findFirstChild("Pants") ~= nil then
            Player.Character["Pants"]:remove()
        end
        if Cloned2:findFirstChild("Pants") ~= nil then
            Cloned:FindFirstChild("Pants"):Clone().Parent = Player.Character
        end
        for i, v in pairs(Player.Character:GetChildren()) do
            coroutine.resume(coroutine.create(function()
            if v:IsA("CharacterMesh") then
                v:remove()
            end
            if v:IsA("Accessory") then
                v:remove()
            end
            end))
        end
    end
    end))
end)

I do not understand why this is not working.

0
I also tried waitforchild still nothing does anything peter21340 41 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

Quick fix, you need to use uppercases.

-- I declared all the locals above.
for i,v3 in pairs(MorphsDir:GetChildren()) do
    local Button = Instance.new("TextButton")
    Button.Size = UDim2.new(1,0,0,50)
    Button.BackgroundTransparency = 1
    Button.Font = "SciFi"
    Button.TextSize = 30
    Button.TextXAlignment = "Left"
    Button.TextColor3 = Color3.fromRGB(255,255,255)

    Button.Text = v3.Name --//Made it uppercase
    Button.Parent = LegionFrame

    Button.MouseButton1Click:Connect(function()
         for i,v2 in pairs(UniformFrame:GetChildren()) do
            if v2.ClassName == "TextButton" then
                v2:Destroy()
            end
         end
         for i,Morph in pairs(v3:GetChildren()) do 
            local Button2 = Instance.new("TextButton")
            Button2.Size = UDim2.new(1,0,0,50)
            Button2.BackgroundTransparency = 1
            Button2.Font = "SciFi"
            Button2.TextSize = 30
            Button2.TextXAlignment = "Left"
            Button2.TextColor3 = Color3.fromRGB(255,255,255)

            Button2.Text = Morph.Name
            Button2.Parent = UniformFrame

            Button2.MouseButton1Click:connect (function()
                print(Button2.Text)
                RemoteEvent:FireServer(Morph, Button)
            end)
        end 
    end)        
end

Another thing is:

local Cloned = FindMorph:FindFirstChild(Button.Name):Clone() --//You cannot clone a name lol
0
Still comes with the same error. peter21340 41 — 4y
0
@peter21340 try local Cloned = FindMorph:WaitForChild(Button.Name):Clone() SpiralRBX 224 — 4y
0
That's not cloning a name, that's cloning an instance with that name... Amiaa16 3227 — 4y
0
Oh, okay. I did it once, but it didn't work, so I figured you can't clone names Cynical_Innovation 595 — 4y

Answer this question