Using GetChildern
it does not execute twice, based on the information given. Something else is going on.
Place1.rbxl (53.6 KB)
Using GetChildern
it does not execute twice, based on the information given. Something else is going on.
Place1.rbxl (53.6 KB)
If you want to add an element to the table every time a new instance is added, you will need to refresh the table obtained by otherFolder
just like that:
local run = game:GetService("RunService")
local otherFolder
local t = {}
run.Heartbeat:Connect(function()
otherFolder = game.Workspace:WaitForChild("otherFolder"):GetChildren()
if #t < #otherFolder then
print(#t)
table.insert(t, os.time())
end
end)
Or you can literally put the variable on the Heartbeat.
But I think use the ChildAdded signal is a better way.
local run = game:GetService("RunService")
local otherFolder = game.Workspace:WaitForChild("otherFolder")
local t = {}
otherFolder.ChildAdded:Connect(function()
table.insert(t, os.time())
end)
I have it like this, but is not working how it should
if #t < #playerFolder:FindFirstChild("Defender"):GetChildren() then
table.insert(t, os.time())
end
I am updating it in the runservice, but still running the code 2 times even if the folder has one element. I have other functions which are the same as this one and they run perfectly.
FWIW, I thought I was talking to the OP at times when I was replying to you⌠my mistake.
I agree with everything youâve said
âŚand @Alchimo99 if you want to update table when the folder contents change, @NiniScripterXQc posted the best way to do this using ChildAdded
.
Best of luck.
I have to check other conditions also not only when something is added to the folder. ChildAdded wont help in my case.
Have you tried using repeat
or while
instead of Heartbeat?
i think it would be good to post your actual code since bugs can appear for all sorts of reasons and giving a rewritten version might remove the bug
or i guess just use the rewritten version if it works
I just used while and is printing 2 time as the run service does.
Can you past this code here, because for me itâs working pretty good even in the Heartbeat
I think you probably made an error that I canât currently see in the condition check because if it does it even in a repeat
or a while
then itâs a condition check error, I guess.
I just re checked and the double execution goes only when I clone the object in the folder, but after the object respawn is working well. I donât know why this is happening since the number of elements is one.
I think you said that you remove the element from the table after checking it? Did I understand correctly? Because if this is the case, and you empty your table and it contains 0 elements and the file has two elements, it is normal for this to trigger twice.
I insert the time in the table only when I clone some mobs. After I clone the mobs I am checking if the attack speed (which is a value) is equal with the os.time() - the time from the table and then I execute the code and I remove the time from the table and the thing repeats until I get some conditions and after that the mobs de spawn or die. And when they respawn again a new time is chosen and the things repeats. The code double execute when I first time clone the mobs, but to the next cycle I noticed that is working good.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.