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

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

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.

3 comments

0

accept rocketer's answer

0

How can i do that?

0

hover over his answer and click on the popup

1 answer

✓ Accepted answer

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.

1 comment

0

That solved my issue. Thank you!

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