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

How do I use events in LocalScript so that I won't have to use a while loop and wait() ?

check2 = true

while check2 == true do if p.Humanoid.Health ~= 0 then rotate() follow() elseif p.Humanoid.Health == 0 then check2 = false end end

is what I tried to use, but it freezes roblox studio,

If I added a wait() the function will take a while to run, hence the result is not instant.

Any suggestions as to what kinds of loop i should use?

1 answer

✓ Accepted answer

hello, so basically you can use RunService. i still don't know what check2 is used for but you still can edit it on your own. RenderStepped won't freeze/crash your game.

game:GetService("RunService").RenderStepped:Connect(function()
	if(check2 == true) then
		if(p.Humanoid.Health > 0) then
			rotate();
			follow();
		end
	else
		check2 = false;
	end
end)

hope it helped. don't forget to accept the answer if it helped you solving your issue.

5 comments

0

oh so I'm trying to make it so that when the player moves his / her character, the npc will face the player and the player's character will face the npc constantly. However if I use wait(), there will be some flickering response, not smooth. So i wanted to remove wait() but the game freezes. Any idea what I should do?

0

yes there's another way to do it actually

0

how?

0

i've editted the answer go and check it out

1

Thanks!!

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