I need help positioning X and Z

I’m trying to make the X and the Z of body position stay the same as the handle of the tool.
I’m making a yoyo and I need the X and Z to be the same and only the Y moving when I click whilst also having the X and the Z be the exact values when the player moved so the yoyo moves with them. If you have an entirely new script idea that would be nice as well with the Y script.

while wait(.05) do
	local Handle = script.Parent.Parent.Parent
	local X = Handle.Position.X
	local Z = Handle.Position.Z
	script.Parent.Position.X = X
	script.Parent.Position.Z = Z

end

This is the locations (This script is the one inside BodyPosition)
image

Error message
image

For more info about this ask me.
Thanks a lot!

Here try this:

while true do

task.wait(0.05)

local Handle = script.Parent.Parent.Parent

local X = Handle.Position.X

local Z = Handle.Position.Z

script.Parent.Position = Vector3.new(X,Handle.Position.Y,Z)

end

It didn’t work and it also didn’t give me an error.

You can’t define a single value in a Vector3, to change one value (say, X) you have to change the whole Vector3.
Instead of doing:

local var = Vector3.new(0, 0, 0)
var.X = 1

You would have to do:

local var = Vector3.new(0, 0, 0)
var = Vector3.new(1, 0, 0)

Or to keep the original values

local var = Vector3.new(16, 18, 30)
var = Vector3.new(1, var.Y, var.Z)

But then it will keep the Y on its place which it shouldn’t. When I click the Y starts moving up and down. (Haven’t made the script yet) and this script keeps the X and the Z the same as the Handles X and Z. Yoyo is the real object but Handle is just a box for reference.

while task.wait() do
	local Handle = script.Parent.Parent.Parent
	local X = Handle.Position.X
	local Y = script.Parent.Position.Y --retains the bodypositions y position value
	local Z = Handle.Position.Z
	script.Parent.Position = Vector3.new(X, Y, Z)
end

Quick note, “wait()” is deprecated, use “task.wait()” instead as it is more accurate.

That was just an example, I imagine you would want to do something like

while wait(.05) do
	local Handle = script.Parent.Parent.Parent
	local X = Handle.Position.X
	local Z = Handle.Position.Z
	script.Parent.Position = Vector3.new(X, whatever y value, Z)
end

?

Everyone’s stuff isn’t working it doesn’t want to assign X or Z. And I need Y to not be affected by this so I can script the Yoyo to go up and down. :confused: I honestly can’t figure out why nothings working.

Try the script I provided above.

I have and its doing the same as everyone’s else. Not giving errors but also not changing the X nor the Z.

You can’t directly assign values to the X, Y or Z components of the “Position” property of a BodyPosition instance, you can only change the value of the entire “Position” property by assigning a Vector3 value.

while task.wait(0.5) do
	local Handle = script.Parent.Parent.Parent
	local X = Handle.Position.X
	print(X)
	local Y = script.Parent.Position.Y --retains the bodypositions y position value
	local Z = Handle.Position.Z
	print(Z)
	script.Parent.Position = Vector3.new(X, Y, Z)
end

Could you try the above and share what is shown in console? It’ll print out the X and Z values every 0.5 seconds.

Absolutely nothing :confused: I’ll try it on something else inside work space and see if it does work or not

Please try the 2nd script I provided, it’s a way to debug the original script you provided.

image

Works on there

But if I equip the tool it just falls down

That’s just printing the X and Z co-ordinates of the handle, I was just making sure that they were being fetched correctly.

This is my script to make the Y go up and down:

local debounce = false

script.Parent.Parent.Activated:Connect(function()
	debounce = false

	while task.wait(0.5) do
		if debounce == false then
			local Y = script.Parent.Position.Y --retains the bodypositions y position value
			script.Parent.BodyPosition.Position = Vector3.new(script.Parent.Position.X, Y, script.Parent.Position.Z) - Vector3.new(0,1.72,0)
			script.Parent.Parent.Activated:Connect(function()
				debounce = true
				script.Parent.BodyPosition.Position = script.Parent.Position
				
			end)
		
		end
	end
end)

Rewrote it to your style of the while loop

Figured out a way to do it without bodyposition!

good job Don!!!

TEXT LIMIT

This text will be hidden