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

Would there be a better or more efficient/resourceful way to make this loop ?

while true do
	for i, player in pairs (players:GetChildren()) do
		if player.Hits >= 20 then
			for i, player in pairs (players:GetChildren()) do
				player.Hits = 0
			end
			local wins = player.leaderstats.Wins
			wins.Value = wins.Value + 1
			player:LoadCharacter()
			break
		end
	end
	--stuff you shouldn't worry about.
end

this is only a part of a script, so don't worry about there being no wait().

A quick summary of this code:

Gets all the players, if there is a player with a Hit more than or equals to 20 then, it will get all the players again and change the value of their Hit to 0, and now it will add a 1 on the original player (with a Hit more than or equals to 20)'s wins and breaks the loop.

So if anyone knows a better way to do this, please tell.

1 answer

✓ Accepted answer

If I were you I would make it into a bindable event (not a remote one so exploiters can't mess with it), I would connect it to whatever sets the player.Hit and see if it's >= 20 at the moment of change and do the code.

If that's not possible for some reason maybe connect a function to .Changed.

Hope this helps :D

2 comments

0

I appreciate the answer :D, however I don't know how to use bindable events yet, because its kinda confusing for me. But I'll try learning it :D.

0

Glad I could help :D There are some really great resources around it (and networking in roblox generally). But for an oversimplified example, it's a function that you can call (or fire) and it doesn't have to be in the same script!

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