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

UDim2.new refuses to add to Position in order to make ImageLabel move?

Asked by
016er 9
4 years ago
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(inp)
    if inp.KeyCode == Enum.KeyCode.L then
        script.Parent.Position = script.Parent.Position + UDim2.new({0.5, 0},{0, 0})
    end
end)

I know for sure that it's this line that it stops at after troubleshooting with print()

script.Parent.Position = script.Parent.Position + UDim2.new({0.5, 0},{0, 0})

gyazo link to hierachy

What can I do to fix this, or is there any better solution to this issue? My current goal is to make an ImageLabel move with the hit of a key, preferably by adding more to the position as I am trying to make a movable 2d character.

0
accept rocketer's answer zadobyte 692 — 4y
0
How can i do that? 016er 9 — 4y
0
hover over his answer and click on the popup zadobyte 692 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Upon further inspection, this appears to be due to the fact that UDim2.new({0.5, 0},{0, 0}) is still seen as {0,0},{0,0}.

Example output from my testing provided below:

> print(UDim2.new({0,0},{0,5}))
{0, 0}, {0, 0}

> print(UDim2.new(0,5,0,5))
{0, 5}, {0, 5}

You can resolve this issue by using script.Parent.Position = script.Parent.Position + UDim2.new(.5,0,0,0) instead.

0
That solved my issue. Thank you! 016er 9 — 4y
Ad

Answer this question