I want when it teleports u to the arena,a sword to appear into ur inventory.
But this error appeared on my output:
" ServerScriptService.Script:42: attempt to index nil with ‘Clone’ "
The code where the error is:
local children = workspace.Ingame:GetChildren()
for i = 1,#children do
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i] -- problem/error
end
Here’s the full code"
local status = game.ReplicatedStorage.Status
local maps = game.ReplicatedStorage.Maps:GetChildren()
while true do
for i = 1,10 do
status.Value = "Intermission: "..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.."!"
local players = game.Players:GetChildren()
wait(4)
for i = 1,#players do
local spawnLocation = workspace.Teleports:FindFirstChild(map.Name)
players[i].Character:MoveTo(workspace.Teleports:FindFirstChild(map.Name).Position)
players[i].Character.Parent = workspace.Ingame
end
local roundLenght = 0
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
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
end
map:FindFirstChildWhichIsA("Tool"):Destroy()
end
if map.Name == "the Lava Race" then
roundLenght = 60
end
if map.Name == "a Sword Fight" then
roundLenght = 120
end
repeat
roundLenght = roundLenght -1
status.Value = "Time Left: "..roundLenght
wait(1)
until roundLenght == 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
if roundLenght == 0 then
status.Value = "Time's up!"
end
wait(3)
map:Destroy()
end
To fix this, Put the sword in ServerStorage then get a referance to it. Then you can clone it and set the clone’s parent to the players starter pack. When the round is over or they die destroy the clone.
if map:FindFirstChildWhichIsA("Tool") then
map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
print("Succes")
else
print("Could not find Sword")
end
try this insted of “map:FindFirstChildWhichIsA(“Tool”):Clone().Parent = children[i]” if the print line “Could not find Sword” works then you need to find the sword