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

How can I replace the checker with something that loops until a specific outcome is met?

I have this set of code here. It works all the way until this part:

for i,v in pairs(mouse.Target:GetDescendants()) do

I want to know how I can replace this with a semi-infinite loop that checks until a certain outcome is made. Heres the full code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mouses = {
	"http://www.roblox.com/asset/?id=409468479"
}
local rs = game:GetService("RunService")
local ObjectInfo = script.Parent:WaitForChild("ObjectInfo")
local TextInfo = ObjectInfo:WaitForChild("TextLabel")
local debounce = true
--
mouse.Icon = mouses[1]
--
rs.RenderStepped:Connect(function()
	if debounce then
		if mouse.Target ~= nil then
			if mouse.Target:FindFirstChild("NameLabel") then
					
				debounce = false
				
				local Start = UDim2.new(0.422, 0,1, 0)
				local Goal = UDim2.new(0.422, 0,0.874, 0)
				TextInfo.Text = mouse.Target.NameLabel.Value
				TextInfo.Position = Start
				local tween = TextInfo:TweenPosition(
					Goal,
					Enum.EasingDirection.InOut,
					Enum.EasingStyle.Quad,
					1,
					true
				)
				wait(1)
				for i, v in pairs(mouse.Target:GetDescendants()) do
					print(v)
					if v.Name ~= "NameLabel" then
						TextInfo.Position = Goal
						local tween = TextInfo:TweenPosition(
							Start,
							Enum.EasingDirection.InOut,
							Enum.EasingStyle.Quad,
							1,
							true
						)
						wait(1)
						print("true")
						
						debounce = true
						
					else
						print("false")
							
						debounce = false
								
					end
				end
			end
		else
			TextInfo.Text = ""
		end
	end
	wait()
end)

Hopefully you guys can help and maybe find a few other errors I might of not seen.

5 comments

0

What are you trying to achieve here? Tweeting a UI if the mouse is over it?

0

*Tweening

0

And what exactly is your error?

0

The code checks if the mouses target part has a NameValue in it, then tweens some text up displaying the NameValues's string. The part that

0

is having the issue is that the for i,v in pairs do part only checks once, so it gets softlocked and the text stays where it is. I need the checker to loop infinitely until the mouse leaves the part with the value.

1 answer

Try:

		local success
                repeat
	                for i, v in pairs(mouse.Target:GetDescendants()) do
	                    print(v)
	                    if v.Name ~= "NameLabel" then
	                        TextInfo.Position = Goal
	                        local tween = TextInfo:TweenPosition(
	                            Start,
	                            Enum.EasingDirection.InOut,
	                            Enum.EasingStyle.Quad,
	                            1,
	                            true
	                        )
	                        wait(1)
	                        success = true
	
	                        debounce = true
	
	                    else
	                        success = false
	
	                        debounce = false
	
	                    end
                            wait()
			until success = true

Sorry for the formatting, I’m on mobile and I didn’t test it, basically we define success as a blank variable, and keep checking if the loop sets it to true. You get the idea.

1 comment

0

Yeah the formatting is on the crazy side, Im unsure how I can put the code in, mind placing it in with the full code so I understand it better?

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