Part Doesn't Get Destroyed

Hello,

so i’ve been trying to like make a car on a road and give it the illusion that it moves.
everyone knows that classic illusion where you move the surroundings instead of the car!
but when i want to move a bush (it works actually but just wait) and it reaches it’s position where it needs to be destroyed (preventing lag) it doesn’t get destroyed…
Code:

local Part = script.Parent
local LimitZ =  71.736

repeat 
	Part.Position -= Vector3.new(0,0,5)
	wait(0.1)
until Part.Position.Z == LimitZ

Part:Destroy()

The Reason Why I Used Position.Z is Because I Want To Put This In ReplicatedStorage
so that i can clone it and spawn it on random X positions .
this script is only the movement the bush will do as soon as it spawns into the map.
to prevent lag because im cloning stuff, i destroy the part after it reaches a certain point.
(it ofc doesn’t work though)

Thanks In Advance!

until Part.Position.Z <= LimitZ

I assume you’re running into the issue where the value of the Z index won’t be exactly your LimitZ so if you do less than or equal to, it should work.

1 Like

wow i should’ve known that…
it’s such an easy fix,
anyway

thanks!

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