My spawner module spawns characters after they die after X seconds
In my game right now I have the respawn time set to 0
This is the snippet that respawns characters:
_G.died:bind(function(plr,char)
wait()--necessary to avoid https://devforum.roblox.com/t/loadcharacter-100-server-crash/358804 with external LoadCharacter calls
if md.respawntime~=1/0 then
if md.respawntime>0 then wait(md.respawntime)end
if plr.Parent and plr.Character==char then
pcall(plr.LoadCharacter,plr)
end
end
end)
_G.died
is basically a bindable event that fires when a character ‘ought to die’
It fires when the humanoid reaches 0 health (when Humanoid.Died fires), but also in other scenarios such as when the character is parented to nil (which occurs when the character is destroyed by reaching workspace.FallenPartsDestroyHeight
)
So since it fires in the second scenario mentioned, it fires when LoadCharacter is also called externally, which means if the wait()
is removed, the crash occurs
For example, I call LoadCharacter
in my admin commands:
cmds.respawn={
level=2,
args={'?plrs',},
func=function(auth,plrs)
for _,plr in ipairs(plrs or{auth,})do
pcall(plr.LoadCharacter,plr)
end
end,
}
So the two solutions I could think of without your patch are that I either add a wait()
or I call my own wrapped LoadCharacter
function which would just have a debounce to ensure LoadCharacter
isn’t nested called:
local spawn do
local spawning={}
spawn=function(plr)
if spawning[plr]then return end
spawning[plr]=true
pcall(plr.LoadCharacter,plr)
spawning[plr]=nil
end
end
But this second solution (while the best), requires me to change my code everywhere LoadCharacter
is used
If you don’t decide to patch this crash, could you let me know so then I will switch to the second solution permanently?
Also, do you know when (if at all) LoadCharacter
errors? The reason I pcall my calls is because some point in the past LoadCharacter
would error; is this fixed?
@RuizuKun_Dev You can see its not called ‘again and again and again’ by adding a print inside that if statement and observing it only prints once
I don’t understand “Why aren’t you using .AncestryChanged and call :LoadCharacter() somewhere else” this is a bug report and I’m showing how it’s possible to crash Roblox
And I’m calling it when the player chats so you can have control over when the player crashes, how would you have written a repro for this?