Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Universal loop not running period?

Asked by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Hello, again. This is going to be frequent to enjoy my company;) I'm doing a lot better with the loops and stuff but I still have an issue with the Universal itemFind loop.

It doesn't seem to be running the proper parts of the Loop, I am getting the Ran notification, although my cursor is on the baseplate I'm not getting the notification of BasePart - ‘Baseplate’ the for i,v loop isn't running period.

I've had a lot of these similar issues with for loops weirdly not starting, I never seemed to find the fix for it:/ The Cursor also freezes in place every time I click...

checkForItem Is set to true when the item Is successfully sent to the proper inventory, or is set if the inventory is full and dismissed

local localPlayer = game:GetService("Players").LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:wait()
local cursor = localPlayer:GetMouse(); local cursorPoint = cursor.Target
local checkForItem
local item_
if (checkForItem) then
    while (checkForItem) do
        print("Ran")
        cursorPoint = cursor.Target
        pcall(function()
            if cursorPoint:IsA("BasePart") then --//Set to 'Tool'.
                print("BasePart - '"..cursorPoint.."'")
                for _, descendant in ipairs(cursorPoint:GetDescendants()) do
                    if findObject(descendant, "BoolValue", "ItemTag") then print("foundItem")
                        item_ = cursorPoint.Name
                        checkForItem = false
                    end
                end
            end
        end)
        wait(.5)
    end
end

0
I take on look at this code, I see on line 1, "lcal" and on line 4, checkForItem isn't even defined greatneil80 2647 — 5y
0
Sorry, that was a copy and paste issue, It’s actually defined Ziffixture 6913 — 5y
0
you need to give us all pertinent information if you want a correct answer DinozCreates 1070 — 5y
0
It’s supposed to run first thing, and if I request an checkForItem Ziffixture 6913 — 5y
View all comments (6 more)
0
we could be lazy and just wrap it in a while loop DinozCreates 1070 — 5y
0
the issue is this only runs once then the if statement wont run again, it either needs to be called at some point or be always running. DinozCreates 1070 — 5y
0
suggesting I wrap it in a spawn thread? Ziffixture 6913 — 5y
0
personally id make checkforitem a bool value and a child of the script, and use .Changed to determine when to run. DinozCreates 1070 — 5y
0
I should probably just wrap it in a function and just call it then? Ziffixture 6913 — 5y
0
that would work fine. i didnt read over the script itself but as far as being called when needed, yes. DinozCreates 1070 — 5y

Answer this question