#Round handler script not functioning proper on death for some reason. (ignore orig msg got deleted)

1 messages · Page 1 of 1 (latest)

sullen hearth
#

got the wrong code earlier mb

sullen hearth
# sullen hearth

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)

rancid peak
#

there's an edit button y'know

rancid peak
# sullen hearth
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)
rancid peak
# sullen hearth
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
sullen hearth
rancid peak
#

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

rancid peak
keen etherBOT
#

studio** You are now Level 5! **studio

rancid peak
#

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

sullen hearth
#

but im not sure

rancid peak
#

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

sullen hearth
rancid peak
sullen hearth
#

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

rancid peak
sullen hearth
#

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

rancid peak
#

is not always just what code. why code matters just as much, if not more than what's actually written.

rancid peak
sullen hearth
#

also sorry idk much abt this svrs rank system
is s1 rank like beginner scripter rank

rancid peak
#

ye scripter skill rank

#

not perfect but nothing ever is and it's better than nothing

sullen hearth
#

currently im looking forward to learning how to script abilities which includes vfx and stuff

#

got any tips on where/how to start

rancid peak
#

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

sullen hearth
#

oh sht alright

#

so i can get experience by working on other ppls projects

#

obviously im going to mention im a newbie and stuff

sullen hearth
#

i havent sent my msg yet cuz of that

#

nvm

#

just found out u need a skill role...

sick trench
sullen hearth
#

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

sick trench
#

Yea, i tried, that also, to expand my skills, but the Moderator contacted me, and said it should be minium, no free at all