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

attempt to index nil with 'Clone' Please help?

Asked by 3 years ago
Edited 3 years ago

When I try to load in a map and give a tool to all players it gives me this error

my script part:


local players = game.Players:GetChildren() for i = 1,#players do if players[i].Character ~= nil then local spawnLocation = math.random(1,#map.Teleports:GetChildren()) players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLocation].Position) players[i].Character.Parent = workspace.InGame end end

how do I fix this

0
I think you are giving us the wrong line of code, because I see not :Clone() here as I guess that's giving the error. If I understand what you are trying to do, it's probably in the code where you :Clone() the map. ew_001 58 — 3y
0
No its cloning the item cadengamer11111 0 — 3y
0
sorry my full code is below. Its on line 51 cadengamer11111 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

My full code:


local status = game.ReplicatedStorage.Status local maps = game.ReplicatedStorage.Maps:GetChildren() while true do for i = 1,10 do status.Value = "Intermission "..15-i wait(1) end local rand = math.random(1, #maps) local map = maps[rand]:Clone() map.Parent = workspace status.Value = "Chosen Minigame: "..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,#map.Teleports:GetChildren()) players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLocation].Position) players[i].Character.Parent = workspace.InGame end end local roundLength = 20 local canWin = true local roundType = "" if map:FindFirstChild("Obby") then roundType = "Obby" roundLength = map:FindFirstChild("RoundTime").Value map.EndPart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and canWin == true then canWin = false status.Value = hit.Parent.Name.." has won!" local plr = game.Players:GetPlayerFromCharacter(hit.Parent) plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value + 1 plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 10 end end) elseif map:FindFirstChild("Sword") then roundType = "Sword" roundLength = map:FindFirstChild("RoundTime").Value local children = workspace.InGame:GetChildren() for i = 1,#children do local clone = map:FindFirstChildWhichIsA("Tool"):Clone() clone.Parent = children[i] end if #children == 1 then children.leaderstats.Wins.Value = children.leaderstats.Wins.Value + 1 children.leaderstats.Points.Value = children.leaderstats.Points.Value + 30 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 local char = workspace.InGame:FindFirstChildWhichIsA("Model") status.Value = char.Name.. "has won!" local plr = game.Players:GetPlayerFromCharacter(char) plr.leaderstats.Wins.Value = plr.leaderstats.Wins.Value + 1 plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 50 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
Ad

Answer this question