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

How to make an if absolute position then?

Before you read my question, please be aware that I'm new to scripting so try to explain it in a simple way so I can understand. So basically what I want to know is how to use the Absolute Position as an if so if the Absolute Position is something specific like 80, 800 then a function is triggered. The problem is the comma because it breaks the script. I'll put the entire Local Script below.

local Player = game.Players.LocalPlayer
local GB = script.Parent
local GF = script.Parent.Parent["Gift Frame"]

GB.MouseButton1Click:Connect(function()
	if GF.AbsolutePosition == 80, 800 then
	GF:TweenPosition(UDim2.new(0, 80, 0, 15), "Out", "Bounce")
	else
	GF:TweenPosition(UDim2.new(0, 80, 0, 800), "Out", "Bounce")
	end
end)

2 comments

0

This is because you’re dealing with a malformed comparison conditional. If you wish to match data, you have to do so within the same datatype. Since AbsolutePosition is a UDim2, you need to write: If (Gui.AbsolutePosition == UDim2.new(0,0,0,0)) then

0

Oh, thank you very much. As I said I just started scripting so I don't know exactly how everything works, this helped a lot.

1 answer

✓ Accepted answer

Since the property AbsolutePosition is a Vector2 object, all you would have to do is to turn your values into Vector2 object. Here's how line 6 would now look instead:

if GF.AbsolutePosition == Vector2.new(80, 800) then

3 comments

0

Haha I read the code wrong, me stupid. :P

0

It worked perfectly, I didn't knew it was so easy to solve. Thank you very much.

0

be sure to accept this answer if it helped you out.

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