Door teleport not working randomly

So, I have a code for the door in my game which seems to randomly stop working as I play.

This is the code:
script.Parent.ProximityPrompt.Triggered:Connect(function(hit)
if hit.Character:FindFirstChild(“Humanoid”) then
for _, player in pairs(game.Players:GetChildren()) do
player.Character.Torso.CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character[“Left Arm”].CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character[“Right Arm”].CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character[“Left Leg”].CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character[“Right Leg”].CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
player.Character.Head.CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame
end
_G.index += 1
wait(1)
end
end)

And I receive the error:
Workspace.Door.Door.Script:4: attempt to index nil with ‘CFrame’

I have no idea why this happens and I came here to see if anyone could help.

Thanks.

First of all wth retroslop of code it is? :skull:
Second of all dont reinvent the wheel
global workspace already exist and is getting auto optimized with GETIMPORT so not only your game.Workspace is pain to look at but is also unoptimized
Third of all you seem to not understand how Joints work in general :anxious_face_with_sweat:

Fourth of all dont use _G/shared unless you are working with plugins.
Fifth of all please wrap code in ```lua

what in the unholy trinity of divine tarnation am i looking at

sir, my good sir, may you please lend me your wisdom and explain how this code even remotely is related to teleporting

may i suggest

player.Character.Torso.CFrame = game.Workspace:FindFirstChild(_G.seed[_G.index]).CFrame

except its uh.. you know a normal path to a part, or PrimaryPart..

Its innit bloody hell of a code it is.
My assumption is that he ties to teleport each body part becouse he doesnt know how joints work.
And it also could be that he tries to use _G cross context Server->Client

i did see that he was setting each body part separately thats why i suggested just teleporting/setting the Torso’s CFrame to the location

also i have no idea why my good sir is using _G for something as simple as Torso.Position = targetPos

alright i do have to agree this was not my best work and now i have fixed it

Fourth of all dont use _G/shared unless you are working with plugins.

why

my hypothesis on what i was thinking in my sleep deprived state was that i have a script where the player is ragdolled and awaiting revival on death so the dead player would have to be teleported? i have no idea why i expected teleporting all parts would make them stick back together or something on the other end

For plugins it is to have presistent data that is expensive to compute etc becouse plugins do get reloaded very often.
As for everything else its just a 100% death to typechecking and any sort of optimizations.

the _G is used for teleporting the player to a certain teleport location taken from a seed table created, nothing to do with the actual teleport really

im just gonna pretend i didnt see that

Blob GIFs | Tenor