I’m trying to make this screen Gui move by taking away it’s current X coordinate by 0.1. However I can’t figure out how to do it without the script crash because it expected a number. I tried assigning the X coordinate to a variable and using that variable - 0.1 but that’s not working either.
local selection_1_X = menu.selection1.Position.X
while true do
if menu:WaitForChild('show_menu').Value == true then
menu:WaitForChild('show_menu').Value = false
print ("Opening menu.")
-- initiating values
menu.Visible = true
menu.selection1.Position = UDim2.new(1.1, 0, 0, 0.12, 0)
menu.selection2.Position = UDim2.new(1.1, 0, 0, 0.31, 0)
menu.selection3.Position = UDim2.new(1.1, 0, 0, 0.5, 0)
menu.selection4.Position = UDim2.new(1.1, 0, 0, 0.69, 0)
menu.selection5.Position = UDim2.new(1.1, 0, 0, 0.88, 0)
for i = 0,62,1 do
menu.selection1.Position = UDim2.new(selection_1_X - 0.1, 0, 0, 0.12, 0)
end
end
wait (0.1)
end
2 Likes
Can you give us the error message?
1 Like
Use TweenService instead, it is way better than what you are doing.
3 Likes
Where does line 17 point to? Also, I thought UDim2
took a maximum of 4 values, not 5
1 Like
This variable doesn’t return a number. You have to use either the Scale or the Offset of it (menu.selection1.Position.X.Scale or menu.selection1.Position.X.Offset
) In this case I think you would want to use the Scale
2 Likes
wait i see what im doing wrong now ill just modify my script now
1 Like
ok thanks it worked im still having some issues where the button is not moving but i think i can fix it by myself
I would use TweenService for this:
show_menu.Changed:Connect(function(bool)
if bool == true then
show_menu.Value = false
menu.Visible = true
TweenService:Create(menu, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = UDim2.new(1, 0, 0, 0.88, 0)}):Play()
end
end)
As a side note having a while loop to check every so often for a change in a BoolValue is very inefficient, listen for the ‘Changed’ event.
1 Like
Thanks for pointing out the thing with the bool. l’ll change it later as it will take a bit of time. I’m not very familiar with the TweenService so I’m not sure if I’ll use it. But I’ll see if I can learn it.