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
print("checking")
checkForPeanut()
wait(3)
end
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
print("checking")
checkForPeanut()
wait(3)
end
Is this in local script?
Do you really need loop for that?
Does this Function Yield? If so, consider adding a coroutine.wrap()() like this, by replacing that function line with this:
coroutine.wrap(checkForPeanut)()
while true do
print("checking")
task.spawn(checkForPeanut())
task.wait(3)
end
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 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()
end
Instance1:GetPropertyChangedSignal(“Name”):Connect(Example)
Instance2:GetPropertyChangedSignal(“Name”):Connect(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.
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
^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!!
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.