Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

can anyone can fix this error it say: attempt to index nil with 'Clone' ?

This is the Code:

local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()
while true do
    for i = 1,10 do
        status.Value = "Intermisson "..10-i
        wait(1)
    end
    
    local rand = math.random(1, #maps)

    local map = maps[rand]:Clone()
    map.Parent = workspace
    
    status.Value = "We'll be playing "..map.Name
    wait(4)
  
    local players = game.Players:GetChildren()
    for i = 1,#players do
       if players[i].Character ~= nil then
           local spawnLocation = math.random(1,#workspace.Teleports:GetChildren())
            players[i].Character:MoveTo(workspace.Teleports:GetChildren()[spawnLocation].Position)
            players[i].Character.Parent = workspace.Ingame
        end
    end

   local roundLength = 50
   local canWin  = true
   local roundType = ""

   if map:FindFirstChild("Obby") then
      roundType = "Obby"
      map.EndPart.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
         canWin = false
         status.Value = hit.Parent.Name.." has won!"
      end
   end)
elseif map:FindFirstChild("Sword") then
      roundType = "Sword"

      local children = workspace.Ingame:GetChildren()
      for i = 1,#children do
      local tool = map:FindFirstChild("Tool"):Clone()
      tool.Parent = children[i]
      end
   end

   map:FindFirstChildWhichIsA("Tool"):Destroy()
   end

   repeat 
       roundLength = roundLength -1
       status.Value = "Time Left: "..roundLength 
       wait(1)
   until roundLength == 0 or canWin == false or #workspace.Ingame:GetChildren() == 0 or (workspace.Ingame:GetChildren() == 1 and roundType == "Sword")
   
   if workspace.Ingame:GetChildren() == 1 and roundType == "Sword" then
      status.Value = workspace.Ingame:FindFirstChildWhichIsA("Model").Name.. " has won!"
   end
   wait(3)
   map:Destroy()

   local players = game.Players:GetChildren()
   for i = 1,#players do 
     if players[i].Character ~= nil then
       players[i]:LoadCharacter()
       end
   end
end

1 answer

It's because you have an extra end on line 49. Remove it and see if it works.

31 comments

0

Now it say attempt to index nil with 'Clone'

0

Well, that's a separate issue though, which line are you getting that error on?

0

Line 43

0

It's most likely because it can't find 'Tool'. Are you sure "Tool" is inside 'map'?

0

Yes

0

Are you able to send a screenshot?

0

wait

0

Do you have a discord to show pic

0

Use Gyazo, or upload your screenshot to imgur.com, then just send me the link to the image.

0

here ya go

0

Ah, I see. Did you supposed to do :FindFirstChildWhichIsA("Tool"), because if you look at line 43, you did :FindFirstChild("Tool"), and obviously there is no tool in 'map' that's called "Tool". You've only got "ClassicSword"

0

so like this map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]

0

Yea, try it and see if it works.

0

ok

0

now it say Expected 'end' (to close 'do' at line 3), got

0

Okay... Can you paste your code on pastebin or something and send me it?

0

You're missing an end on line 44.

0

the line 44 is code: end

0

Yes, there needs to be another end there, to close off the if statement.

0

Just move that end down and then add another one

0

ok

0

it say again attempt to index nil with 'Clone'

0

The same line?

0

yes line 43

0

Okay.. Whilst you're testing, check if the Tool is still there, if it is send a screenshot please.

0
0

To be honest, I'm not quite sure why you're getting this error, I'm testing with the exact same code you have on line 43, and it seems to be working for me, all I can say is that the issue is that it can't find the tool in the map. So make sure that the tool is still in the map when it's being cloned. if this issue still persists, I'd suggest just making another question about it.

0

Thx

0

No problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.