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

Having trouble with Vector3 to know where's the vector's position, Please help ? [FIXED + ANSWER]]

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)

3 answers

if script.Parent.Position == Vector3.new(pos)

would probably be the best for your situation

1 comment

0

Doesn't move anymore, And there's no errors

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

1 comment

0

also, some syntax is wrong

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.

1 comment

0

I don't want it to go back to A, I want it to go to B when you click it when it's at A, and go back to A when you click it when it's already at B.

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