I've been looking and I can't find a way to be able to loop a whole script. This is because I am trying to keep looping a check that sees if a player has something in their inventory. Instead, if I were to but a while loop into the section it only loops the check but I want it to loop the whole script because there is a gun script under it (this is the "this gun for fps" assault rifle script.) Because it is only looping the check for the players inventory the gun does not function. Please help.
Thank you!
(script)
while true do --Supposed to loop the whole script but it only loops until the end. wait() if game.Players.LocalPlayer.Backpack:FindFirstChild("MinionWeaponSpeed") then FireRate = 3.75/30 else FireRate = 5/30 end end --------------------- TEMPLATE ASSAULT RIFLE WEAPON --------------------------- -- Waits for the child of the specified parent local function WaitForChild(parent, childName) while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end return parent[childName] end
ok, know you found a solution but for future use: you can do that with coroutines
coroutine.wrap(function() while true do `code` end end)() -- <-- dont forget this or it won't run
also:
local loop = coroutine.wrap(function() while true do `code` end end) -- somewhere else in the script when you want to do the loop loop()
it will run in a different thread so the script can do other things while that loop is happening