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

How to keep checking stats every four seconds?

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.

2 comments

0

You should tab that a bit better.

0

I didn't tab it like that, it broke after I pasted it here.

2 answers

✓ Accepted answer
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

3 comments

1

Thanks

0

Remember to accept the answer if it helped you :D

0

You can just do while wait(4) do, replacing the 'true' and removing the wait(4) below.

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.

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