Hello Developers! I made a script system that chooses a random map and teleports the player to the map, and after a countdown timer it teleports the player back to the lobby and destroys the chosen map.The problem is that the map is not destroying.
Can you help me?
Here is my script:
local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.Lobby.SpawnLocation
local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChosenMap.SpawnLocation
--- Teleport ---
InGame.Changed:Connect(function()
if InGame.Value == true then
wait(1)
for _, player in pairs(game.Players:GetChildren()) do
local character = player.Character
character.HumanoidRootPart.CFrame = ChosenMap.SpawnLocation.CFrame
ChosenMap:Clone().Parent = workspace
end
else
wait(1)
for _, player in pairs(game.Players:GetChildren()) do
local character = player.Character
character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
ChosenMap:Destroy() ------------------------------------------ THE PROBLEM
end
end
end)
--- Intermission and game Timer ---
local function roundTimer()
while wait() do
for i = 10, 1, -1 do
InGame.Value = false
wait(1)
Status.Value = "Game starts in:"..i
end
for i = 10, 1, -1 do
InGame.Value = true
wait(1)
Status.Value = "Time left:"..i
end
end
end
spawn(roundTimer)
I think I may know the problem, so basically your getting the chosen map from replicated storage and then your trying to delete it from the same path, your going to have to get the path of where the map is after it was chosen and index it with its name and then destroy it that way
Sometimes it’s not really I script error I once had something replicated storage and tried destroying it after it didn’t rlly work. Try sending a remote event with the chosen map variable and have a different script in serverscriptservice which destroys it.
Maybe if you sent the full script it would help us get to the problem because it looks like youve only sent a piece of the code, or is there another part?
Yeah thats what i suggested to him earlier but he’s saying it isn’t working but hes also saying that he sees ChosenMap inside of workspace, and it’s apparently not giving any errors aswell