I am pretty new and learning as I go… and have been reading that it is very important to ‘clean up’ your variables when you are done with them. (Sorry, I don’t know the vocabulary…)
I am curious if I am understanding this concept correctly.
This little bit of script constantly tracks the player position…
-- track player location
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while humanoidRootPart do
local xPos = math.round(humanoidRootPart.Position.X / chunkSize, 0)
local zPos = math.round(humanoidRootPart.Position.Z / chunkSize, 0)
print(player.Name," is at ",xPos," , ",zPos)
wait(.25)
end
end)
end)
From what I have read, I believe I should be ‘cleaning up’ the xPos and zPos variables? Otherwise all the old coordinate data just piles up in the void as new data is set?
So, would this fix that?..
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while humanoidRootPart do
local xPos = math.round(humanoidRootPart.Position.X / chunkSize, 0)
local zPos = math.round(humanoidRootPart.Position.Z / chunkSize, 0)
print(player.Name," is at ",xPos," , ",zPos)
xPos = nil -- ADDED THIS
zPos = nil -- ADDED THIS
wait(.25)
end
end)
end)
Or is this completely unnecessary? Am I understanding this correctly?..
Any advice is appreciated!
Thanks!