I'm trying to make tear gas, or smoke grenade or something, idk, but it will work when using greater than or equal to, but not less than or equal to. And I want it so when they're 5 studs are closer, they are damaged.
local function damagePlr() player.Character.Humanoid.Health=player.Character.Humanoid.Health-10 end local mag=(player.Character:GetModelCFrame().p-toxicC.Position).magnitude -- while mag<=5 do damagePlr() wait(3) end --
You only update mag
once, before the loop. Each time the loop iterates, it will be using the same distance. You have to recompute the distance each iteration of the loop.
Besides that, this code will only work if the player starts in range.
If they aren't range, the loop stops immediately and will never start again.
If you want something to happen whenever a condition is met, it generally should look like this:
while true do local mag = (player.Character:GetModelCFrame().p - toxicC.position).magnitude if mag <= 5 then damagePlr() end wait(3) end