EDIT : To anyobody who wanted to do what I wanted to do, Here's the code
local function onClicked() print("successfully clicked") if script.Parent.Position == Vector3.new(INSERT POINT A) then script.Parent.Position = Vector3.new(INSERT POINT B) else script.Parent.Position = Vector3.new(INSERT POINT A) end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
So I'm having trouble and I'm kind of confused, I'm making a drawer that can be pulled and pushed, Only problem is I don't know how I could make if the Vector3 in a certain position when clicked, It gets pushed back to it's original position :
function onClicked() -- funcc print("successfully clicked") script.parent.Position = Vector3.new(-6.834, 7.5, 59.8) -- new vector3 when clicked if script.parent Vector3(-6.834, 7.5, 59.8) then -- i suck but here's the problem, i script.parent.Position = Vector3.new(-9.257, 7.339, 59.476) -- go back to original position print("successfully clicked") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
if script.Parent.Position == Vector3.new(pos)
would probably be the best for your situation
function onClicked() print("successfully clicked") script.parent.Position = Vector3.new(-6.834, 7.5, 59.8) if script.parent Vector3(-6.834, 7.5, 59.8) then script.parent.Position = Vector3.new(-9.257, 7.339, 59.476) print("successfully clicked") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
in this, you are changing script.parent.position to something else first , which means it is not equal to the one which is in that if statement, which means thw 'if' statement wont run
This problem is easy to solve, and you just need to know the proper syntax (language of the programming.) Basically use the operator ==
it checks if the thing is true. Also there is a lot of spelling errors, which I won't comment on.
local function onClicked() print("successfully clicked") script.Parent.Position = Vector3.new(-6.834, 7.5, 59.8) wait(3) --I suggest you keep this in order to see the part moving. if script.Parent.Position == Vector3.new(-6.834, 7.5, 59.8) then --You need to reference the position. script.Parent.Position = Vector3.new(-9.257, 7.339, 59.476) end end
I also added a wait()
function so that you can see the position move from A to B, and then back to A.