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

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

Asked by
Foridex 46
4 years ago

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.

0
What are you trying to achieve here? Tweeting a UI if the mouse is over it? NickIsANuke 217 — 4y
0
*Tweening NickIsANuke 217 — 4y
0
And what exactly is your error? NickIsANuke 217 — 4y
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 Foridex 46 — 4y
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. Foridex 46 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

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? Foridex 46 — 4y
Ad

Answer this question