well that’s more complicated, I use a module to stock the loop’s data, in there I detect when a player die and if he respawn we will teleport him in a special place, it’s a custom spawnpoint basically. Here is the module. The module’s parent is my script. The LastChanged option is changed when the player touch another checkpoint.
local players = game:GetService("Players")
local class = {}
players.PlayerAdded:Connect(function(player)
local userId = player.UserId
class[userId] = {}
class[userId].LastPlayed = nil
player.CharacterAdded:Connect(function(character)
if class[userId].LastPlayed ~= nil then
print(class[userId].LastPlayed)
character:WaitForChild("HumanoidRootPart").Position = class[userId].LastPlayed:FindFirstChild("Attachment").Position -- bug there
end
end)
end)
players.PlayerRemoving:Connect(function(player)
table.remove(class, player.UserId)
end)
return class
This is wrong. table.remove is for arrays, and it goes hand-in-hand with table.insert. What you are using is a hashmap instead, aka a dictonary. To remove it, you just assign the value to nil.
thanks, the problem is that I cannot use :FindFirstChild() after using a value the error is “attempt to index nil with :FindFirstChild”, that logic but I cannot find what the problem is
Then it should not print the error because I have a condition that detect if it’s not nil, so I use it in another script which is the parent of the module.