Script can't find something that should exist

I have this piece of code and I have a folder in workspace, everytime I do something like game.workspace.workspacestoragefolder it says its not in the workspace but when I got look in workspace in play testing it there.

Try workspace:WaitForChild(ā€œworkspacestoragefolderā€)

2 Likes

It seemed not to work, it puts the maps into workspace and not the folder which was not intended at all as well the flags dont go to the folder inside of workspacestorage.

Whatā€™s the folderā€™s name, and where is it located ?

1 Like

WorkspaceStorageFolder game > Workspace
FlagFolder game > workspace > WorkspaceStorageFolder > FlagFolder I can provide the script if you would like.

1 Like

Could you show a little bit of the script so I can understand better ?

1 Like

local MapChangerManager = {}

ā€“ ROBLOX Services

local Players = game.Players

ā€“ Local Variables

local Events = game.ReplicatedStorage.Events

local WorkspaceStorage = game.Workspace:WaitForChild(ā€œWorkspaceStorageFolderā€)

local Maps = game.ServerStorage.MapSave

ā€“ Public Functions

function MapChangerManager:MakeNewMap()
local NewMap = math.random(1,4)
for _, child in ipairs(game.ServerStorage.GameModesFolder.CaptureTheFlag:GetChildren()) do
if child.Name == ā€œFlagStandā€ then
child.Parent = WorkspaceStorage:WaitForChild(ā€œFlagStandFolderā€)
end
end
if NewMap == 1 then
local ClonedMap = Maps:FindFirstChild(ā€œCastle Mapā€):Clone()
ClonedMap.Parent = WorkspaceStorage:WaitForChild(ā€œMapā€)
elseif NewMap == 2 then
local ClonedMap = Maps:FindFirstChild(ā€œForest Mapā€):Clone()
ClonedMap.Parent = WorkspaceStorage:WaitForChild(ā€œMapā€)
elseif NewMap == 3 then
local ClonedMap = Maps:FindFirstChild(ā€œCastle Mapā€):Clone()
ClonedMap.Parent = WorkspaceStorage:WaitForChild(ā€œMapā€)
elseif NewMap == 4 then
local ClonedMap = Maps:FindFirstChild(ā€œForest Mapā€):Clone()
ClonedMap.Parent = WorkspaceStorage:WaitForChild(ā€œMapā€)
end
end

function MapChangerManager:DeleteMap()
WorkspaceStorage.Map:ClearAllChildren()
for _, child in ipairs( WorkspaceStorage.FlagStandFolder:GetChildren()) do
if child.Name == ā€œFlagStandā€ then
child.Parent = game.ServerStorage.GameModesFolder.CaptureTheFlag
end
end
end

return MapChangerManager

The maps seems to be cloning into the map folder correctly, I donā€™t see any problem with the cloning.

Yeah it clones but it goes to the workspace let me send a screenshot but it doesnt go to the folder let me send the errors wait 1 second

Wait I fixed it! It was an error with the main script as well what you said earlier!

Alr nice to hear, glad to be of help.

1 Like

I appreciate the help! Must get going now! :grinning:

Not sure how to fix your error, but I wanted to point out a useful simplification you can do.

Instead of doing:

you can do:

local MapNames = {"Castle","Forest","Castle","Forest"}
local ClonedMap = Maps:FindFirstChild(tostring(MapNames[NewMap]))
if ClonedMap then
	ClonedMap = ClonedMap:Clone()
	ClonedMap.Parent = WorkspaceStorage:WaitForChild("Map")
end

:slight_smile:

1 Like

Thank you! I have been wondering how to do something like that cause my scripts get lengthy as well it mostly picks the number 1. I really appreciate it you have made my life easier!

1 Like

Is it normal for it to have a red underline under it?

Where at? (and no, red underlines usually mean errors and the script could break)

function MapChangerManager:MakeNewMap()
for _, child in ipairs(game.ServerStorage.GameModesFolder.CaptureTheFlag:GetChildren()) do
if child.Name == ā€œFlagStandā€ then
child.Parent = WorkspaceStorage:WaitForChild(ā€œFlagStandFolderā€)
end
end
local ClonedMap = Maps:FindFirstChild(tostring(MapNames[NewMap]))
if ClonedMap then
ClonedMap = ClonedMap:Clone()
ClonedMap.Parent = WorkspaceStorage:WaitForChild(ā€œMapā€)
end
end

its at the part that says NewMap it says unknown global ā€˜Newmapā€™

Itā€™s because you forgot to add the random part:
local NewMap = math.random(1,4)
and the table of names I provided.

1 Like

ohhhhhhhhhhhhh I deleted it out the script

so if theres 2 maps do i change the random value to 1,2?