Can't loop function

I tried looping a function every 3 seconds. However, no matter what I do this loop doesn’t work. I need the function looped constantly, it’s a simple loop with a few lines of code.

while true do
yes, the script is enabled. yes, function code is correct (but may be spaghetti)
1 Like

Is this in local script?

Do you really need loop for that?

1 Like

Does this Function Yield? If so, consider adding a coroutine.wrap()() like this, by replacing that function line with this:


1 Like
while true do

yes. it’s a script that checks certain ‘requirements’ for peanut.

no i don’t think that would work, doesn’t yield

Where in the explorer is your script placed? Is it server or client sided?

Example: LocalScript in game.StarterPlayer.StarterPlayerScripts

How is a peanut tracked? Can you show us this function and or the whole script?

Multiple scripts track many ‘requirements’ based on what the player does, and I’ve tracked these using name changes, since I’m not very experienced in scripting I thought that changing a simple property like that could work, and yes I made sure it doesn’t screw up referencing in scripts.

In the peanut function I did the same, so just checking names :person_standing: pretty simple

for a bit of background info, the peanut can be cooked but under certain conditions

I first did this but then I placed it into a script and then in a folder I keep some of my scripts in.

I asked where do you have you script in the explorer and is it client or server sided.

Also as a side note you should learn :GetPropertyChangedSignal() As you can detect something when a name is changed and not use a while true loop at all

Here is as Example:

local function Example()




@izNatt Do what I did above, but change the example function to the function your using. And Change Instance1 and Instance2, to the 2 objects you have in that if statement.

1 Like

Oh sorry I thought you meant where in the workspace, that confused me. But it is in the workspace in a folder along with other scripts

it ran once but it didn’t loop

U are sure that u dont get any error?

no errors, nothing in the output

Thank you, that seems much simpler. I just edited my script and am playtesting, this may take a bit

1 Like

^Edited my post for support without using a loop if you want to switch to that

Thank you so much, it worked, I’m sure to use this in many other scripts!!

1 Like

Your so welcome. Just going to mention but it works for basically any property, and not just name. But yea this is an important thing in scripting that I use a lot.

1 Like