Playtime Reward

You would have to break the loop when the player leaves the game or it will repeat forever considering its while. My system does not require this because it gets terminated when the server is closed.

I mean if you have to break (not sure if you really HAVE to)

you just do

while task.wait(1) do
    if not player then
        break
    end
end

If you create a new loop for every single player, you are required to break the loop when the player leaves the game or else it will waste resources looping on a player that doesn’t exist (and throwing errors.) furthermore I don’t think making a new loop for every single player than joins the game is very optimized or easy to track. Instead I would use my solution of having a single while loop which loops through all the players to preform actions.

I think you’re missing the point. OP is trying to reward individual players based on their own playtime. Creating a single loop that iterates through every player every 60 seconds would increment the reward value of every player in the server.

I see what you mean,
tested out the loop on a 1 player server in studio and it does in fact go on forever.

but a simple checking if they are still in the game, and if they are break the loop, fixes the issue you state

if you do an if statement inside of the loop to determine of that individual player has met the requirement, it will only reward individual players.

for example:

if player.time > 60 then
 --reward player
end

this only rewards individual players. NOT all players.

Why u guys didnt noticed me im bored :rage:

i wanna ask another question about the while loop :smiley_cat:

i actually use repeat loop to get the timer end.but then i had a issue.the repeat loop only worked for once.so this got me mad and hasnt fixed it for 2 days.(i solved it with something annoying property but that game has gone because i selled my account)

i tried the while loop it works but it goes to -1 even i check if the number is lower than i gave.

Which one is the best to loop? while or repeat?

im using it on my own rooms fanmade game.

It depends. repeat is great if you are trying to do something until something happens, hence the syntax:

repeat --[[Do something]] until --[[Something happens]]

while loops are great when you just need to repeat something forever, however, you can use while loops to detect something changing as well:

local WAIT_TIME = 60

local value = true
local run_time = tick()

while value do
    if tick() - run_time >= WAIT_TIME then
        value = false
    end
end

It usually depends on the use case of the loop.

Uhh okay thanks for helping i understand now :face_with_diagonal_mouth:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.