Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make this stop after becoming true?

The following script works fine; but it constantly prints "yes" over and over. I would like to just print once if within the area, and just print "no" once if not in the area.

local player = game.Players.LocalPlayer
local render = game:GetService("RunService")
local work = game.Workspace


render.RenderStepped:connect(function()
	if (player.Character.Head.Position - work.shopTouch.Position).magnitude < 5 then
		print("yes")
	else
		print("no")
	end
end)

1 comment

0

Are you sure using renderstepped is the best option? Something simpler like a while loop could be better for performance.

1 answer

✓ Accepted answer

Try making a true or false variable that stops it from looping the print when the user enters & exits the area. So if the user enters the area it sets the variable to true & stops it from printing anymore. And when they're out of area then it sets the variable to false.

local player = game.Players.LocalPlayer
local render = game:GetService("RunService")
local work = game.Workspace

inArea = false

render.RenderStepped:connect(function()
    if (player.Character.Head.Position - work.shopTouch.Position).magnitude < 5 then
		if inArea == false then
			inArea = true
		wait(0.01)
		print("yes")
	end
    else
		if inArea == true then
        print("no")
	inArea = false
    end
end)

Hope this helped!

1 comment

0

Needed some tweaking, but it worked. Accepted.

This discussion is preserved as it was. New answers, comments, and votes are closed.