Hey everyone. I’m trying to make a command that the admins of the script can change the map. Though, only map 1 and 2 work, map 3 and 4 don’t. I’ve tried this and the other inside my full code as of finding the part and deleting it:
if not game.Workspace.Map1 then
game.Workspace:FindFirstChild("Map2"):Destroy()
end
Here’s my full script, sorry if it’s a bit messy I’m a starter in programming.
--// ADMINS
local admins = {"jees1"};
--// MAPS
local map1 = game.ServerStorage.Map1
local map2 = game.ServerStorage.Map2
local map3 = game.ServerStorage.Map3
local map4 = game.ServerStorage.Map4
--// ADMIN CHECK
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
print("User is an admin")
isAdmin = true;
break;
end
end
return isAdmin
end
--// CODE
function onChatted(msg, speaker)
if checkAdmin(speaker) then
msg = string.lower(msg)
if msg == "!changemap map1" then
map1:Clone().Parent = game.Workspace
game.Workspace:FindFirstChild("Map2"):Destroy()
if not game.Workspace:FindFirstChild("Map2") then
game.Workspace:FindFirstChild("Map3"):Destroy()
if not game.Workspace:FindFirstChild("Map3") then
game.Workspace:FindFirstChild("Map4"):Destroy()
if not game.Workspace:FindFirstChild("Map4") then
print("Changed to map 1")
end
end
end
elseif msg == "!changemap map2" then
map2:Clone().Parent = game.Workspace
game.Workspace:FindFirstChild("Map1"):Destroy()
if not game.Workspace:FindFirstChild("Map1") then
game.Workspace:FindFirstChild("Map3"):Destroy()
if not game.Workspace:FindFirstChild("Map3") then
game.Workspace:FindFirstChild("Map4"):Destroy()
print("Changed to map 2")
end
end
end
elseif msg == "!changemap map3" then
map3:Clone().Parent = game.Workspace
game.Workspace:FindFirstChild("Map1"):Destroy()
if not game.Workspace:FindFirstChild("Map1") then
game.Workspace:FindFirstChild("Map2"):Destroy()
if not game.Workspace:FindFirstChild("Map2") then
game.Workspace:FindFirstChild("Map4"):Destroy()
if not game.Workspace:FindFirstChild("Map4") then
print("Changed to map 3")
end
end
end
elseif msg == "!changemap map4" then
map4:Clone().Parent = game.Workspace
game.Workspace:FindFirstChild("Map1"):Destroy()
if not game.Workspace:FindFirstChild("Map1") then
game.Workspace:FindFirstChild("Map2"):Destroy()
if not game.Workspace:FindFirstChild("Map2") then
game.Workspace:FindFirstChild("Map3"):Destroy()
if not game.Workspace:FindFirstChild("Map3") then
print("Changed to map 4")
end
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)onChatted(msg, player) end)
end)
Any help is appreciated, thank you!