Hello, SpinTower! Lets take a look at some of your code, and review it.
for i = 2, 0, -1 do
Status.Value = "Intermission"
wait(0.20)
Status.Value = "Intermission."
wait(0.20)
Status.Value = "Intermission.."
wait(0.20)
Status.Value = "Intermission..."
wait(0.20)
end
Here you’re using a for-loop to change the value of a, well the entire reason of using a for loop is so you don’t have to perform the method that you did! Rather than changing the Status.Value every .20
seconds, how about we reduce your code so that it does it by itself?
local intermissionText = 'Intermission...' -- This is defining the variable, intermissionText, as "Intermission"
--#intermissionText is the length of intermissionText, it returns a number value.
for i = 1, #intermissionText do
Status.Value = string.sub(intermissionText, 1, i)
wait(.20) --Waits 0.20 seconds before running again!
end
In effect, this reduces your code down to only 4 simple lines of code. You should also do the same thing we did here for the Teleporting players
loop and the Setting up game
loop!
Lets move onto the availablespawnpoints.
Your loop currently loops through and says if the player has a character, then move them to the first spawn point available- then remove that spawn point from the availablespawnpoints
’s array. You are not physically destroying the spawn-part from workspace. You could solve this by doing:
local spawnPoint = availablespawnpoints[1]
character.HumanoidRootPart.CFrame = aspawnPoint.CFrame
spawnPoint:Destroy() --This will physically remove the tile from the workspace.
for i, tile in pairs(Tiles:GetChildren()) do
tile.Touched:Connect(function(character)
tile.Name = player.Name
end)
table.insert(tiless, tile)
end
In this code, you’re creating a new connection every time the tile is touched… but you have no debounce! So this code will run very single time a player is has touched the title. If I were you, I’d insert a BoolValue
into the tile, named IsOccupied
and if IsOccupied == true then return end
.
Though, you should be sure to destroy all of these connections that you’ve made at the end of the round. Else, sever memory will become super clogged and begin to lag.
Now, moving onto the final code you put:
for i, tile in pairs(tiless) do
if tiless[i].Transparency == 1 then
tiless[i]:Destroy()
table.remove(tiless, i)
end
There’s simply no need to index tiless[i]
when you could simply do tile.Transparency
. Ultimately brining your code down to:
for i, tile in pairs(tiless) do
if tile .Transparency == 1 then
tile:Destroy()
table.remove(tiless, i)
end
Keep in mind I’m not saying this is the ultimate solution to your code, I am saying these are some things you could to do make your code look cleaner, and run more efficient. You should be sure that you are not just removing the TILE from the array of tiles. You have to physically destroy the tile item, else it will still appear in workspace! When you do tile[i] all you’re doing is removing the tile from the array of tiles. The tile object/instance will still exist.