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

mouse freeze/unfunctional loop?

Asked by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

This is yet another attempt at my pickUp Script like I said before. I'm slowly making it more universal, I've gotten to a decent point where most of it is. The problem I'm having is the item identifier loop, it's a bit hard to explain, so here's the Script, it'll be a lot easier to understand where I'm getting at if you have at least intermediate knowledge

function findObject(instance,object,handle)
    local itemDecendants = instance:GetDescendants()
    for _,object in ipairs(itemDecendants) do
        if (object:IsA(object) and object.Parent:IsA(instance.ClassName) and object:IsDescendantOf(instance)) and object.Name == handle then
            print(object:GetFullName().." "..instance); return object
        end
    end
end

local localPlayer = game:GetService("Players").LocalPlayer
local cursor = localPlayer:GetMouse(); local cursorPoint = cursor.Target
local item_
while (cursorPoint ~= item_) do
    if (cursorPoint:IsA("BasePart")) then --//Set to 'Tool'.
        for _, descendant in ipairs(cursorPoint:GetDescendants()) do
            if type(descendant) == 'boolean' and findObject(descendant, "BoolValue", "ItemTag") then
                item_ = cursorPoint
            end
        end
    end
    wait(.5)
end

local item = workspace:FindFirstChild(item_)
print(item.Name.."-"..item:GetFullName())

I'm getting nothing out in the output, and it seems like the while loop isn't running at all, this is my first grasp at a universal loop, so don't judge, please fill me in on efficiency tips or other issues.

The Cursor also freezes when I click anywhere in workspace, what's wrong?!

if this is still confusing ask me to re-explain it and I'll try my best

thanks!

0
cursorPoint will not update if the mouse target changed. Also, why are you checking if the descendant is a boolean? That will never be true. User#24403 69 — 5y
0
also while looking at your function findObject, you have namespace issues. one of findObject's arguments is object and the second variable in your for loop is also object, due to scope object is now descendant and not the argument. object:IsA(object) will never be true GoldAngelInDisguise 297 — 5y

1 answer

Log in to vote
0
Answered by
Imperialy 149
5 years ago

put the local cursorpoint inside of the loop

0
put this as comment, not as answer. yHasteeD 1819 — 5y
Ad

Answer this question