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)
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
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. I honestly can’t figure out why nothings working.
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.
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)