function checkpointService:getCheckpoints(tID, wID)
local world = worlds:FindFirstChild("WORLD_"..wID)
if not world then return end
local trails = world:FindFirstChild("trails")
if not trails then return end
local trail = trails:FindFirstChild("TRAIL_"..tID)
if not trail then return end
local obby = trail:FindFirstChild("obby")
if not obby then return end
local checkpoints = obby:FindFirstChild("checkpoints")
if not checkpoints then return end
return checkpoints:GetChildren()
end
#Any suggestions on how to simplify this
1 messages · Page 1 of 1 (latest)
There's not much of a point in making your code this robust
Do you not trust that the input values to your function will be sane?
i figured, i changed it to this cause i wont exactly know if all trails will contain checkpoints
function checkpointService:getCheckpoints(tID, wID)
local checkpoints = worlds:FindFirstChild("WORLD_"..wID)
:FindFirstChild("trails")
:FindFirstChild("TRAIL_"..tID)
:FindFirstChild("obby")
:FindFirstChild("checkpoints")
if not checkpoints then return end
return checkpoints:GetChildren()
end```
waitforchild
server script
what would happen with an infinite yield would this break the function
probably
I might also just get the descandents and check for the checkpoint attribute
but I dont want to loop through the whole obby parts
local function FindDescendant(parent:Instance?,d,...)
return if d then FindDescendant(parent:FindFirstChild(d),...) else parent
end
function checkpointService:getCheckpoints(tID,wID)
local checkpoints = FindDescendant(worlds,"WORLD_"..wId,"trails","TRAIL_"..tID,"obby","checkpoints")
return checkpoints and checkpoints:GetChildren()
end```
but like i said that's really meh
it always returns nil
I just want it to not break wehn i fuck the data structure up
wehn a player would run this function and it gives an error can he use the function again?
i do not recommend using code you don't understand
I understand what the code does i think this is a general question wehn a function has an error can you call the function again
ther we go local function FindDescendant(parent:Instance?,d,...) return if d then FindDescendant(parent:FindFirstChild(d),...) else parent end
one-liner 😄
alr thats too complicated now
--!strict
local function FindDescendant(p:Instance?,d,...)
return if d then FindDescendant(if p then p:FindFirstChild(d) else nil,...) else p
end```
anyway, yeah that was my point, its not simplifying it