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.
First of all wth retroslop of code it is?
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
Fourth of all dont use _G/shared unless you are working with plugins.
Fifth of all please wrap code in ```lua
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
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