#Round handler script not functioning proper on death for some reason. (ignore orig msg got deleted)
1 messages · Page 1 of 1 (latest)
basically when a player dies the player is meant to be removed from the "playing" table
but after testing it out from the seems of it they get removed once or smth and then it doesnt work again on any other rounds
this is the section
i got no clue if its an error with the code ive written or if its an error with functions overlapping with one another
Round handler script not functioning proper on death for some reason. (ignore orig msg got deleted)
there's an edit button y'know
changeTeams.OnServerEvent:Connect(function(player)
player.Team = lobbyTeam
table.insert(lobby, player)
print(lobby)
end)``` this doesn't catch the case where this event is fired twice, use insertExclusive function (check if it already exists in the table before inserting another copy of it, i.e if not table.find(lobby,player) etc)
local spawns = {}
local function getSpawns()
for _, spawners in pairs(spawnFolder:GetChildren()) do
table.insert(spawns, spawners)
end
end
local function randSpawn()
getSpawns()
local randSpawn = spawns[math.random(1, #spawns)]
print(randSpawn)
return randSpawn
end
...
inGame.Changed:Connect(function()
if inGame.Value then
for _, player in pairs(lobbyCopy) do
local selectedSpawn = randSpawn()
``` this is a memory leak - every time you call to get a random spawn location, which happens whenever inGame is set to true, presumably to start a round, you call getSpawns() again for every player which inserts an additional copy of all the spawnlocations into the table, ad infinitum. this doesn't change the odds of any particular spawnlocation being chosen, but it is a memory leak that will eventually crash your game servers if given enough time
nah mb should of clarified but that event should only get fired once
its basically to continue past a cutscene
should, but if it doesn't by any means, which exploiters can do, it will flood that table with copies of the player. i'm still tracing the rest of your code
the way you use checkPlayers() is fairly bad, you will learn a lot from making the mistakes you have done with it. you do need a check like this but the way you've done it is rather poor, i'm sure that's already obvious to you
so it looks like you probably getting errors here
yep
** You are now Level 5! **
specifically here: ```lua
inGame.Changed:Connect(function()
if inGame.Value then
...
else
for _, plr in pairs(game.Players:GetPlayers()) do
plr.Team = lobbyTeam
table.remove(playing, table.find(playing, plr))
table.insert(lobby, plr)
...
end
end
end)```
coz i was looking for where you reset players from playing into lobby and it's right there
yes i just cant figure why
i personally feel like its cuz stuff are overlapping as a result of loosing track of the task.wait() time in some of the functions
but im not sure
table.remove(playing,nil) will error, and this can (and will) happen depending on the order of the game.Players:GetPlayers() against who the winner is. if player 1 is the winner, then they were already removed from the playing table in the getWinner() function: ```lua
local function game()
...
round()
...
end
local function round()
...
if getWinner() then
break
end
...
end
local function getWinner()
if #playing == 1 then
...
inGame.Value = false
table.remove(playing, 1)
table.insert(lobby, winner)
return true
end
end
I'm fairly certain your inGame.Changed connection fires *after* the thread calling getWinner() yields, because changed events will create a new thread (similar to task.spawn). it would help if you show your output window / screenshot it
so when it gets to here table.remove(playing, table.find(playing, plr)), table.find(playing,plr) returns nil, and you cannot table.remove nil
fairly certain this is the error. output window screenshot will prove if this theory is correct
ah alr so should i try moving ingame.Value = false after
table.remove
show output window so i can see the exact error you're getting
im not actually getting an error in output
but it just doesn't work
which is what is making me confused
🥀
hol up im testing rn
alr back mb for the wait
made a few changes now the death thing seems to be working good
the getWinner()
however
i tested with a friend and we realised if
theres like 2 players remaining for example
and both players die at same time
the checkWinner function i believe is to slow to process it fast enough
because the round just continues until the timer ends
these are the changes we did
if table.find() then
..
end
yep these are edge cases, you will learn them as you get more practice and experience working with things like this. is what i meant about the checkPlayers function. you need lots of checks like this. you're doing well so far. it's not perfect, but slowly spiralling towards better and more working. well done 👍
ty ty
i made a lot of mistakes when i first started learning coding like 2-3 months ago
first was relying on chatgpt...
and thinking if i understood the code it wrote i would be able to code if i tried to do the same thing
when i actually tried to do a proper code for once i realized just how diff it is to write one compared to reading one
and that made me quit coding
is not always just what code. why code matters just as much, if not more than what's actually written.
this is the key distinguishing skill needed for s1 rank, you're not quite there yet but this is how you get there. anyone can do what i call stitching code, where they can take existing code and stitch it together with ducttape, hopes, and dreams, and maybe get something that kind-of works. writing from scratch is a whole different tier of skill that all s1's should have.
yep im getting there
that 200 code script i wrote was 95% me but like 10 - 20 lines were from chatgpt
also sorry idk much abt this svrs rank system
is s1 rank like beginner scripter rank
ye scripter skill rank
ranks are mostly used for #💵︱hiring and #👷︱for-hire as a form of vetting skill levels
not perfect but nothing ever is and it's better than nothing
currently im looking forward to learning how to script abilities which includes vfx and stuff
got any tips on where/how to start
start by continuing exactly as you are
a very simple round system is nothing compared to trying to make proper tsb clone
things like, if you can't make a +1jump/sec game, you aren't making a combat game ;p
if you can't make a button simulator, you aint making much else
monster in a maze like color or die is good for getting started with npcs and pathfinding
i have made all 3 of those ;p
plus full simulator from scratch
oh sht alright
currently im thinking of putting myself up #👷︱for-hire for free
so i can get experience by working on other ppls projects
obviously im going to mention im a newbie and stuff
@rancid peak will i get in trouble for not including any past work in #👷︱for-hire
i dont really got past work
i havent sent my msg yet cuz of that
nvm
just found out u need a skill role...
you don't but by reading rules, you have to set minium 500 robux,
that shouldnt be an issue
if im doing it for free
cuz its not like i can scam
im quiet litterally doing it for free
i think thats only an issue if ppl want payment below 500 robux
Yea, i tried, that also, to expand my skills, but the Moderator contacted me, and said it should be minium, no free at all