- What do you want to achieve? Keep it simple and clear!
I’m trying to make a round system that clones a part into workspace from replicatedstorage and then destroy it but it only works some of the times I test it.
-
What is the issue? Include screenshots / videos if possible!
It says this:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have changed up the script multiple times but it keeps indexing nil with destory, I have looked for many solutions and I’ve tried many different ideas but it doesn’t seem to work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
- This is my code so far, it probably isn’t the most optimal or organized piece of code but it seems to work sometimes. (which has me confused). My goal is to clone a part from ReplicatedStorage to Workspace and then destroy it
-- services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
-- variables
local requiredPlayers = 1
local roundlength = 30
local intermissionLenth = 15
local startinglenth = 5
local number = math.random(1,3)
local map = ReplicatedStorage.Maps:GetChildren()
local number = math.random(1, #map)
local statusText = ""
local statusUpdate = ReplicatedStorage:WaitForChild("StatusUpdate")
local waitpart = game.Workspace.Waitpart
local function waitforplayers()
statusText = "Waiting For Players..."
repeat
task.wait(0.5)
statusUpdate:FireAllClients(statusText)
until
#Players:GetPlayers() >= requiredPlayers
end
local function startingRound()
local newmap = map[number]
newmap:Clone()
newmap.Parent = workspace
--MapToClone.Parent = workspace
print("Map Found!")
for i = startinglenth, 0, -1 do
statusText = "Starting Next Round...("..tostring(i)..")"
statusUpdate:FireAllClients(statusText)
task.wait(1)
end
end
local function startRound()
waitpart.CanCollide = false
end
local function endRound()
waitpart.CanCollide = true
--local number = math.random(1,3)
--local MapToDestroy = workspace:FindFirstChild("Map"..number)
local newmap = game.Workspace:FindFirstChild(map)
newmap:Destroy()
print("Map Gone!")
end
while true do
-- Intermission
for i = intermissionLenth, 0, -1 do
statusText = "Waiting For Next Round...("..tostring(i)..")"
statusUpdate:FireAllClients(statusText)
task.wait(1)
end
waitforplayers()
startingRound()
startRound()
--GameRound
for i = roundlength, 0, -1 do
statusText = "Round In Progress...("..tostring(i)..")"
statusUpdate:FireAllClients(statusText)
task.wait(1)
end
endRound()
end