Position script not working

Ok so I have a script which is not working there are no errors with it so what I need it to do is move a block to a position when a different block is clicked.
When I click the block it does move the block just to a area witch it is not meant to it goes right on top of a model not in it.

Here is the script

Part = script.Parent
Model = game.Workspace:WaitForChild(“Water”)

Part.ClickDetector.MouseClick:Connect(function()
wait(2)
Model:MoveTo(Vector3.new(102.5, -4.235, -13.5))
wait(2)
Model:MoveTo(Vector3.new(102.5, -3.735, -13.5))
wait(2)
Model:MoveTo(Vector3.new(102.5, 2.265, 37))
wait(2)
Model:MoveTo(Vector3.new(102.5, 2.765, 37))
wait(5)
Model:MoveTo(Vector3.new(102.5, -4.735, -13.5))

end)

2 Likes

Try to do local Model = workspace.Water instead

Edit:

local Part = script.Parent

1 Like

Sorry I tried that and it still didn’t work when I click the block it moves just not to the right position.

1 Like

Could you screenshot what it’s supposed to do and what it’s actually doing?

2 Likes

Do you know how to use roblox debugging tools?
Perhaps try printing these variables after implementing them

1 Like

This is before I press


And this is after I press the button

Its meant to go to each position and then go back to start but it goes to this position witch is not any of the positions I’ve told it to go.

1 Like

What’s the position of the part when it’s like this?
opera_M9HVS6HbL0

1 Like

this is the position >> 102.5, 6.265, -13.5 <<

1 Like

How would I do that.
And what is the debugging tools.

1 Like

The :MoveTo() function actually calculates for collisions. You cannot move a model inside another model using MoveTo().

Since you’re trying to move it inside the tree, it just moves the blue platform above it.

1 Like

If you do not want to account for collisions, use :SetPrimaryPartCFrame() and insert a cframe of the Vector3 position you would want to move it to, like:

Model:SetPrimaryPartCFrame(CFrame.new(102.5, -4.235, -13.5))
1 Like

If your water is not a model from the looks of it you can just set it’s position like a normal basepart;

model.Position = Vector3.new(102.5, -4.235, -13.5)
1 Like

I tried what you said for me to do and it is still not working.

1 Like
local Part = script.Parent
local Model = workspace:WaitForChild("Water")

local Rotation = table.pack(Model:GetPivot():ToOrientation())


-- Yes, it's not the best idea
Part.ClickDetector.MouseClick:Connect(function()
	task.wait(2)
	Model:PivotTo(CFrame.new(102.5, -4.235, -13.5) * CFrame.fromOrientation(table.unpack(Rotation)))
	task.wait(2)
	Model:PivotTo(CFrame.new(102.5, -3.735, -13.5) * CFrame.fromOrientation(table.unpack(Rotation)))
	task.wait(2)
	Model:PivotTo(CFrame.new(102.5, 2.265, 37) * CFrame.fromOrientation(table.unpack(Rotation)))
	task.wait(2)
	Model:PivotTo(CFrame.new(102.5, 2.765, 37) * CFrame.fromOrientation(table.unpack(Rotation)))
	task.wait(5)
	Model:PivotTo(CFrame.new(102.5, -4.735, -13.5) * CFrame.fromOrientation(table.unpack(Rotation)))
end)

2 Likes

If you need to maintain the original orientation of the model you can instead use an instance method which does not alter/modify/change the orientation of the model.

local Part = script.Parent
local Click = Part.ClickDetector
local Model = workspace:WaitForChild("Water")

Click.MouseClick:Connect(function()
	task.wait(2)
	Model:TranslateBy(Vector3.new(0, -10, 0))
	task.wait(2)
	Model:TranslateBy(Vector3.new(0, 0.5, 0))
	task.wait(2)
	Model:TranslateBy(Vector3.new(0, 5.5, 50.5))
	task.wait(2)
	Model:TranslateBy(Vector3.new(0, 0.5, 0))
	task.wait(5)
	Model:TranslateBy(Vector3.new(0, -6, -50.5))
end)

For the thread’s poster, consider using more uniform numbers (0.5, 1, 1.5 etc.) with as few decimal places as possible, this is to improve the code’s readability.

1 Like

Doesn’t TranslateBy move using an offset?
If you were doing this and you wanted the original positions you’d have to do something along the lines of Model:GetPivot():ToObjectSpace(CF).Position
That’s worse imo

1 Like

Original position shared here.

1 Like