Neeed help With a Position

So i am using repeat and i want to know how to check when a part has hit a certain position then it stops going up.

Presuming the script is inside the part in question.

local part = script.Parent
local end_part = Instance.new('Part')
end_part.Name = "end_part"
end_part.Position = Vector3.new(0,100,00)
end_part.Anchored = true
end_part.Parent = workspace

part.Position = Vector3.new(0,0,0)

repeat
	part.Position += Vector3.new(0,1,0)
until part.Position ~= end_part.Position

haven’t tested it out though

repeat task.wait() until part.CFrame == CFrame.new("Your CFrame")

It still keeps going up, also that ~= made it not even go up

You should just check the Y component, and use >= to make the comparison work with slight inaccuracies.

repeat
  part.Position += Vector3.new(0, 1, 0)
until part.Position.Y >= 100

However, you probably don’t actually want to do this. If you’re just trying to make a part go up to a certain height, you can tween it directly to that height:

local part = workspace.Part
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3) -- takes three seconds
local moveUp = 20 -- studs
local targetPosition = part.Position + Vector3.new(0, moveUp, 0)
local tween = tweenService:Create(part, tweenInfo, { Position = targetPosition })
tween:Play()
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.