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

Script isnt detecting the correct position of UI?

Asked by 3 years ago
Edited 3 years ago

When updating the position of a frame, tweening or not, the script checks the specific Y Scale value on the Frame to see if it doesn't equal the value it gets set to

The script initially is supposed to ignore the if statement, and go to the else statement meaning since the frame hasn't been tweened yet, and once another tween is called, the if statement clears the tween basically

For Example:

message = values.Message.Changed:Connect(function()
            if (values.Message.Value) then
                UI.MessageFrame.Visible = true;
                if (UI.MessageFrame.Position.Y.Scale ~= .9) then
                    if (UI.MessageFrame.Position.Y.Scale > .79) then
                        local start = tick();
                        repeat wait() until (UI.MessageFrame.Position.Y.Scale <= .82 or tick()-start >= .5)
                        task.wait(1)
                    end
                    tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.9, 0)});
                    task.wait(1.3)
                    if (values.Message.Value) then
                        UI.MessageFrame.Message.Text = values.Message.Value;
                        tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.79, 0)});
                        wait(2.5)
                        tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.9, 0)});
                        wait(1)
                        UI.MessageFrame.Visible = false;
                    end
                else
                    warn"ya"
                    UI.MessageFrame.Message.Text = values.Message.Value;
                    tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.79, 0)});
                    task.wait(2.5)
                    tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.9, 0)});
                    wait(1)
                    UI.MessageFrame.Visible = false;
                end
            else
                if (UI.MessageFrame.Position.Y.Scale ~= .9) then
                    tweenObj(UI.MessageFrame, 1, {Position = UDim2.new(0.822, 0, 0.9, 0)});
                    wait(1)
                    UI.MessageFrame.Visible = false;
                end
            end
        end)

Segment that isn't running properly:

if (UI.MessageFrame.Position.Y.Scale ~= .9) then

At this portion, when I print the Y Position, it prints 0.89999999764121, instead of 0.9, as in the position property of the frame at the exact moment says {0.822, 0},{0.9, 0}

Does anyone have any related issues to this? I'm only posting this because it has always worked before, and now all of a sudden it starts with this issue. I feel as if this is a ROBLOX API issue at the moment.

1 answer

Log in to vote
0
Answered by
Xeqro 20
3 years ago

It's not about ROBLOX api, it's floating point issues as every other programming language also does have a problem about it. I'm not here to say why does it cause the issue as you can just search up "floating point issue" on Google and there will be plenty of explanation about it. Anyways, since ROBLOX caps their floating point on the third floating digit, you can do:

local function Round(number, increment)
    return math.round(number * (1 / increment)) / (1 / increment)
end

if Round(UI.MessageFrame.Position.Y.Scale, 1 / 10 ^ 3) ~= .9) then

Not sure if this works, but if it can solve your problem please mark this answer as the solution

Ad

Answer this question