Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

mouse freeze/unfunctional loop?

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!

2 comments

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.

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

1 answer

put the local cursorpoint inside of the loop

1 comment

0

put this as comment, not as answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.