Script that Detects Position Change not Working

This script is supposed to detect when a projectile reaches a minimum altitude, and then detonate. It doesn’t work, and it doesn’t print the test print statement I added to it. What did I do wrong? Here’s the script:

local it = script.Parent
function boom()
	local explosion = Instance.new("Explosion")
	explosion.BlastRadius = 25
	explosion.BlastPressure = 20000
	explosion.Position = it.Position
	explosion.Parent = game.Workspace
	wait()
	it:Destroy()
end

it.Changed:Connect(function()
	print("oof")
	if it.Position.Y <= -1 then
		boom()
	end
end)
2 Likes

For efficiency reasons, the Position property or any other physics property don’t fire Change or events from :GetPropertyChangedSignal.

1 Like

should I use a while loop instead?

No, but you could try RunService.Heartbeat

2 Likes

Not too familiar with this. How would I utilize it and would a while loop be how much less effective?

A while loop just wouldn’t be efficient.

Documentation for heartbeat: RunService | Documentation - Roblox Creator Hub

Events are more optimal. They only fire when they need to.

1 Like

Yeah, just tried it out. Worked fine. Thanks!

A script I ave that gets the position of a part has worked for years and today has stopped functioning, error log says it can’t index the position of the part. Engine bug or some change they made??

I guess you’d have to use https://developer.roblox.com/en-us/api-reference/event/RunService/Heartbeat too