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

Help with click detector?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

When I click a model moves to 1,1,1 but when I click again, I want the model to move where it was before you clicked the first time.

Part = script.Parent
Model = game.Workspace:WaitForChild("Model")

Part.ClickDetector.MouseClick:connect(function()
    Model:MoveTo(Vector3.new(1,1,1))
end)

1 answer

Log in to vote
1
Answered by 8 years ago

You need to save the coordinates of where it was in the first place

local x, y, z = 0, 0, 0

part.ClickDetector.MouseClick:connect(function()
    if Model.Position.X ~= 1 and Model.Position.Y ~= 1 and Model.Position.Z ~= 1 then
        x = Model.Position.X
        y = Model.Position.Y
        z = Model.Position.Z

        Model:MoveTo(Vector3.new(1,1,1))
    else
        Model:MoveTo(Vector3.new(x,y,z))
    end
end)
0
Model does not use "Position" FiredDusk 1466 — 8y
Ad

Answer this question