I’m trying to put a Highlight into every player left alive on a certain team if all their spawns have been destroyed.
The problem is the Highlight won’t even spawn, like it won’t detect the players.
I’m not even really sure how I could go about debugging this and couldn’t find anything on DevForum.
elseif TeamSpawns.Knights.SpawnsLeft.Value == 0 then
if #RemainingKnights ~= 0 then
for _, Knight in pairs(RemainingKnights) do
local Highlight = KnightHighlight:Clone()
Highlight.Parent = Knight.Character
delay(0.01, function()
Highlight.Enabled = true
end)
end
end
end
Highlight instances are capped to around 20 in a game at once, so just a small optimization, put everything you want a highlight on in a model and have the highlights adornee set to that model instead. 2 instances for 10 players is better than 10 for 10.
Anyway, add prints everywhere, see how many times the code is running and what data its reading.
--// Before the first if statements:
print(TeamSpawns.Knights.SpawnsLeft.Value)
--// Before you check how many are left:
print(#RemainingKnights)
--// In the for loop:
print(Knight)
If the first one prints the wrong output, you’ve scripted the spawns left system wrong.
If the second one only prints once, the check is ONLY happening once and never again.
If the second one prints several times but prints 0, you may be indexing your table wrong. #table checks the keys in a table, counting up from 0 and stopping when the next index is nil.
Running this code in the command line shows that: local table1 = {["me"] = 1} local table2 = {[1] = 1, [3] = 2} print(#table1) print(#table2) > Outputs 0, 1
Essentially, tables need to be formatted like this to work:
{
[1] = Character,
[2] = Character
}
Not like this:
{
["PlayerName"] = Character,
["PlayerName"] = Character
}
If you need help reformatting removing keys from tables, this should work with how tables are supposed to be formatted:
This is not a direct solution however it might be optimal to do. Instead of creating a highlight for each player, parent all alive players to a model and add one highlight with the adornee set to the model. This will help with the hard cap for the amount of highlights you can have and you only need to enable or disable one highlight instead of adding a new one for each player.
elseif TeamSpawns.Knights.SpawnsLeft.Value == 0 then
for _, Knight in RemainingKnights do
local Highlight = KnightHighlight:Clone()
Highlight.Enabled = true
Highlight.Parent = Knight.Character
end
end
What do you consider retroslop, cuz I use studs and old meshes and everything in the game is before or in 2016 with everything being on a 0.5 grid. Would you still consider that retroslop?
I’m trying not be like grow a garden and just plaster the texture over everything. I genuinely like the style and I’m trying to do it right. Also thanks a lot for the help.
In this context im talking about code specifically and use of depracated and absolutelly unneeded and illogical features aswell as bloat in it that kills perfomance.
Please ignore the term this other person used for your code! Truthfully, deprecated code is in fact, not “retroslop”, and we try to maintain a respectful environment in the Dev Forum when possible!
Deprecated code is unreliable and has poor compatibility with modern Studio, and that is the real reason you should not use it. Try not to concern yourself with such terms being used against your creations.
Your “retro” style of choice for your game is perfectly fine.
You should prioritize having fun and building something you are proud of, while learning essential information and improving your development abilities!
Godspeed, Fellow Developer!
No you don’t, ipairs is when you want to get both the index and the value of the index. A regular loop would work just fine.
local RemainingKnights = {"Player1", "Player2", "Player3"}
for _, knight in pairs(RemainingKnights) do
print(knight) --> Prints Player1, Player2, Player3
end