Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago
if script.Parent.Position == Vector3.new(pos)

would probably be the best for your situation

0
Doesn't move anymore, And there's no errors Cioss_Team 14 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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

0
also, some syntax is wrong zeusplayz2005 5 — 4y
Log in to vote
0
Answered by 4 years ago

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.

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. Cioss_Team 14 — 4y

Answer this question