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

If then statements with two Positions ImageLabels?

This doesn't seem to work... With errors in Output.

--add n.Changed:connect(function() on top of here when target of script is not script.Parent
local x = script.Parent
local n = script.Parent.Parent.Parent.OnesPlace.ImageLabel
--here is where you would add n.changed
if n.Position == UDim2.new(0,28,0,0)
	then
x.Position = x.Position + UDim2.new(0,30,0,0)	
end

--If ImageLabelOne moves to a certain position then ImageLabelTwo, which is the Parent of the script, moves as well. x is ImageLabelTwo and n is ImageLabelOne.

3 comments

0

I noticed I made mistake with UDim2.new I did (0,28,0.0) instead of (0,28,0,0)

0

Note to self: To get the preexisting X & Y Scale and offset properties and apply them to the UDim2.new() put in "UDim2.new(Gui.Position.X.Scale, Gui.Position.X.Offset [In this case Gui.Position.X.Offset +30 because we are moving an ImageLabel in Position], Gui.Position.Y.Scale, Gui.Position.Y.Offset)"

0

@Simnico99

1 answer

##Problem

I do not believe that you can do arithmetic on two UDim2 values. If you can, please let me know down below.


##Solution

Anyway, you'll want to get the X & Y Scale and Offset values from the ImageLabel's properties. Once you gather all those you can set them as the UDim2 values and do arithmetic in the UDim2.new() function.


##Final Script

local x = script.Parent
local n = script.Parent.Parent.Parent.OnesPlace.ImageLabel

if n.Position == UDim2.new(0,28,0,0) then
    x.Position = x.Position + UDim2.new(x.Position.X.Scale,x.Position.X.Offset + 30, x.Position.Y.Scale,x.Position.Y.Offset)   
end

--If ImageLabelOne moves to a certain position then ImageLabelTwo, which is the Parent of the script, moves as well. x is ImageLabelTwo and n is ImageLabelOne.

######If this answered your question, do not forget to hit the accept answer button. If you have any questions, feel free to comment down below and I can get back to you.

4 comments

0

Hi, thank you for the info. I did not know it was possible to do arithmetic with prexisting values. But this script didnt go through well for me in studio. I had previously accepted an answer on this question prior to your arrival. I'd like to know what happened to it so I can both refer to both yours and his information from your answers for future reference. @M39a9am3R

0

Also, yes, it is very possible to do arithmetic with two UDim2.new values. @M39a9am3R

0

On line 5 (of the second code example), why go through all that? Just using the original code that was there originally was enough; doing what you've done for line 5 is unnecessary, and a waste of time; also, that'll increase the Position of the GUI greatly:

0

It essential says "Position + Same Position + X 30 Offset (Pixels)." Was this intended?

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