Waiting until align Position end

  1. What do you want to achieve? Keep it simple and clear!
    Topic
  2. What is the issue? Include screenshots / videos if possible!
    Topic
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I looked through few topics, but found nothing good

Code:

while true do
   print("Test")
	local random = Random.new()
	local randomTrajX = random:NextNumber(64, -64)
	local randomTrajZ = random:NextNumber(64, -64)
	local part = Instance.new("Part")
	part.Name = "EndPoint"
	part.Anchored = true
	part.Transparency = 1
	part.Position = Vector3.new(randomTrajX, 24, randomTrajZ)
	part.CanCollide = false
	part.Parent = script.Parent
	local attachment = Instance.new("Attachment")
	attachment.Parent = part
	attachment.Name = "Attachment1"
	script.Parent.AlignPosition.Attachment1 = attachment
	if (script.Parent.Attachment0.Position - attachment.Position).Magnitude < 0.01 then
		part:Destroy()
	end
	task.wait(0.1)
end

It just doesn’t create anything(OLD)
Currently can’t detect align position end

1 Like

Are you sure? There are some errors, did you specify the parent correctly? Script works? if (script.Parent.Attachment0.Position - attachment.Position).Magnitude < 0.01 then won’t interfere?

where is script located? whats is it workspace?

Yeah i just realised that was problem. It destroyed part instantly. Now it correctly works. Though i need to do it somehow with local script, but i think that already for different topic.

Although quick question then. It kinda can’t reach magnitude to less than 0.1 and part doesn’t destroy now and clone trillion times.

that is, after creating n number of parts, it stops?

Nah it just run infinitely, these parts are bad for performance. It should destroy after. While i was looking for script to wait for align position completion only what i found was loop with magnitude(i use same, but for me it just skips that if and runs code again. Maybe coroutine could help?).

Magnitude 0.01 is possible only if the positions are equal. But even after that, your loop will continue, you need to do some kind of check and enter break there to stop spawning.
Example:

if (script.Parent.Attachment0.Position - attachment.Position).Magnitude<1 then
	part:Destroy()
	break
end

Don’t really help on that point. I already done something like that, it still produce them infinitely

This means that the condition is not met and its chance is very small

Maybe better calculating exact time for part finish align position and then use it in task.wait? ((script.Parent.Position - script.Parent.EndPoint.Position).Magnitude/Velocity)

What should this script do? Why are these parts

This is just animation for Photons(They are first currency in my incremental game(i’m making something inspired by Grass Cutting Incremental)). They will light up territory(game goal is to make everything bright in world of darkness) and fly by random trajectory. They have an end part, where they should finish align position, before running next one.I randomize trajectory(or position for end part) and then photon fly to endPos via alignPosition

I think you can make a limit of N phantoms, if there are more of them, then wait until it becomes less

Not Photons getting multiply creating. End points for ONE Photon are creating massively

Btw about that, it works fifty by fifty. Sometimes it wait ~70-80% correctly, but sometimes like 40%. So this is bad method

I’m sorry, I don’t understand what you need, maybe someone else can help you

Wait i have an idea. How could i set position of align position in OneAttachment mode? As i understood it should just move part to position, so i don’t really need to destroy any parts

You just need to move it indefinitely as far as I understand