Number Value not being changed from script

Ok so I am still new to scripting so this might be a very simple mistake but I am making a script that makes it so wherever I place a part on the map they will move to a specific location.

clickdet.MouseClick:Connect(function()
	
	if Xvalue<finalx then
		while Xvalue~=finalx do
		Xvalue=Xvalue+.5
		wait(.1) 
		
		end
	elseif Xvalue>finalx then
		while Xvalue~=finalx do
			Xvalue=Xvalue-.5
			wait(.1) 
		end
	end
end)

this is the script to change the x value of the part. I have one for the Y value but they are pretty much identical and once I figure out how to fix this one I can just mirror it to the y value script. Pretty much how it works is I have 2 number values in the part. One for the x value and one for the y value. When the part is placed somewhere on the map I change the x values and y values to match up with the current position of the part. Then I have a separate part and once clicked it is supposed to fire the script to make this part work. It is supposed to check if if it greater than or less than a variable I made called finalx which is the final x position of the part. and then I have a third script that it constantly setting the x value of the part to the x value number value in the part. When I run the script I get no errors but for some reason the xvalue in the part doesnt change at all. I know the click detector works. I think I explained pretty much everything but if you have any questions just ask down below. I would really appreciate the help.

What is Xvalue? If you put
XValue = part.Position.X
and then update XValue, you will only update the value of XValue, not the actual position. You should instead put
part.Position = part.Position + Vector3.new(0, 0.5, 0).
Note that vector components are read-only, you cannot do
part.Position.X = part.Position.X + 0.5.

Also put more spaces in your code, it hurts to see everything jammed together that tightly…

Xvalue is a numbervalue object I put into the part. the variable is
local Xvalue=part.Xvalue.Value
the way that I change the position of the part is
part.Position=Vector3.new(Xvalue, Yvalue, Zvalue)

You need to set XValue = part.XValue and then use XValue.Value in the rest of the code. The variable XValue just stores a number, if you change it to part.XValue then it will be a pointer to the number value, which is what you want.

1 Like

Yeah you got a big brain. Thank you so much.