i have this function that is supposed to remove the player from the table if “cube” doesn’t exist. instead if the cube exist it constantly adds and removes player from the table. but when it removes it removes 26x exactly each time. i’ve wrote this several different ways. and still same thing. except one way i wrote it. it did remove only one time each time it removed. still had the continuous loop though. very strange. i’ve never had this issue. i’m assuming it has something to do with the character. doesn’t make any sense.
this is what the script is now.
function module.remove(player, person)
if not table.find(module.has, player) then return end
local me = table.find(module.has, player)
for i, v in ipairs(person:GetChildren()) do
if v:GetAttribute("cube") then return end
table.remove(module.has, me)
print"removed me"
end
end
I’ve had this same issue that I had to deal with this week, the remove method was not actually removing it from the table. Try setting the index to nil instead of using table.remove
function module.remove(player, person)
if not table.find(module.has, player) then return end
local me = table.find(module.has, player)
for i, v in ipairs(person:GetChildren()) do
if v:GetAttribute("cube") then return end
module.has[me] = nil
print"removed me"
end
end
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local human = character:WaitForChild("Humanoid")
if not human then return end
while character.Parent == nil do
character.AncestryChanged:wait()
end
local newAnim = human:LoadAnimation(anim)
while wait() do
module.add(player, character)
module.remove(player, character)
local result = module.check(player)
if not result then continue end
if playing then continue end
if result then
newAnim:Play()
playing = true
print"im supposed to be playing.."
end
end
end)
In this block, you’re running the print command for every child of the character. Maybe it has to do with that? Pretty sure that if you put a “print(#person:GetChildren())” before the loop you will see it print 26 as well.
no it’s not supposed to be called when i have the cube. just called when i don’t have the cube. the while loop, i mean, is not the issue. least i doubt. because if it was then i’d have issues like this with the other scripts. they are just inserting player to table if has cube. and removing player from table if doesn’t have cube. but as long as player has cube. its constantly getting added and removed when he has it. hes only supposed to be removed if he doesnt have it