Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to keep checking stats every four seconds?

Asked by 8 years ago
Edited 8 years ago

Hi.

How can I check every single player's leaderstats.reputation.Value every 4 seconds?

--do this to every player:
if(Player:FindFirstChild("leaderstats")) then
            if(Player.leaderstats.reputation.Value < 0)then
        --do things
        end
end
wait(4)
--repeat

Uh, one more thing. There is this function, getPlayerFromCharacter(). I'm looking for a function that would do the opposite thing.

0
You should tab that a bit better. iFlusters 355 — 8y
0
I didn't tab it like that, it broke after I pasted it here. Programical 653 — 8y

2 answers

Log in to vote
3
Answered by 8 years ago
Edited 8 years ago
while wait(4) do
    for _, Player in pairs(game.Players:GetPlayers()) do
        --do this to every player:
        if Player:FindFirstChild("leaderstats") then
                    if Player.leaderstats.reputation.Value < 0 then
                --do things
                    end
        end
    end
    --repeat
end

As for your question involving getting the character from the Player, the character is a child of the Player, so you can index it the way you'd index any child.Player.Character

Hope this helps you

1
Thanks Programical 653 — 8y
0
Remember to accept the answer if it helped you :D DepressionSensei 315 — 8y
0
You can just do while wait(4) do, replacing the 'true' and removing the wait(4) below. iFlusters 355 — 8y
Ad
Log in to vote
2
Answered by 8 years ago

Don't.

Use Events instead. I am highly against using polling-based solutions where Roblox provides an event-based alternative. Use Value.Changed instead.

Reputation.Changed:connect(function(newRep)
    if newRep < 0 then
        -- Do things.
    end
end)

If you need the Player, you'll want to stick that inside of a PlayerAdded just as DepressionSensei's answer suggests.

Answer this question