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

How could I improve this script?

I'm making an free-for-all round for a FPS game. In my script, when there is only one player left standing, that player is awarded 100 Cash (Player.leaderstats.cash), but if 3 minutes (180 seconds) go by and there are more than one players still alive, they are all killed and no Cash is awarded.

  function ffa()
					local countdown = coroutine.wrap(function()
					local timer = 180
					while wait(1) do
					timer = timer - 1
					if timer == 0 then
					if #Players >= 1 then
					for i, v in pairs(Players) do
					local char = v.Character or repeat wait() until v.Character
					local hum = v.Humanoid or repeat wait() until v.Humanoid
					hum:TakeDamage(100)
					elseif #Players == 1 and timer > 0 then
					hum:TakeDamage(100)
					Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 100
					end
					end
					end
					end
	end

On line 9, I get the following error: "Expected identifier, got "repeat"'

I tested it and it does not work. Thanks for your help.

1 answer

✓ Accepted answer

A repeat loop does not yield a value, only function calls and indexes return a value. Move repeat wait() until v.Character one line up and replace the next line with local hum = char:WaitForChild("Humanoid")

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