hey, so i made this game where you need to press buttons and stuff on floors that are randomly picked out, every time you press all the buttons on the floor, the map unloads and picks out a new one
it kind of works at first, but then it doesn’t.
as in, it’ll generate a map, and when i press all the buttons and wait the time i specified in the script it doesn’t do anything afterwards
the code i wrote in the main script is here
local counter = 1
local chosenmap
function chooseSpawnPoints(spawnblocks) -- folder is the spawn parts folder we specified in the while loop
local tableA = spawnblocks:GetChildren()
local tableB = {} -- the Winner table
local tabALength = #tableA
local maxspawnblocks = math.random(1,tabALength)
for i = 1,maxspawnblocks do
local randomNumber = math.random(1,tabALength)-- choosen a random # within the tables max index.
local choosen = tableA[randomNumber] -- grab the value
if choosen ~= nil then
table.insert(tableB,choosen)-- insert the choosen spawn block into the winner table
table.remove(tableA,randomNumber)-- remove from the spawn block table so we do not get it again
end
end
return tableB
end
local maps = game.ReplicatedStorage.maps:GetChildren() -- get a list of all the maps
local chosenMap = maps[math.random(1,#maps)]
chosenMap = chosenMap:Clone()
chosenMap.Parent = game.Workspace
local choosenblocks = chooseSpawnPoints(chosenMap.spawnblocks) -- changed the function a bit. It needs a parameter which is the instance it will loop through
for i, block in pairs(choosenblocks) do
local button = game.ReplicatedStorage.Button:Clone()
button:SetPrimaryPartCFrame(CFrame.new(block.Position))
button.Parent = game.Workspace.Buttons
block:Destroy()
end
local buttonsPressed = game.Workspace.ButtonsPressed
local buttons = game.Workspace.Buttons:GetChildren()
buttonsPressed.Changed:Connect(function(property)
if property == "Value" then
if buttonsPressed.Value == #buttons then
wait(5)
chosenMap:Destroy()
buttons:Destroy()
wait(5)
chosenMap:Clone()
chosenMap.Parent = workspace
end
end
end)
any help is appreciated, thank you in advance