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

Update function not working?

game.Players.PlayerAdded:connect(function(player)
		local stats = player:findFirstChild("leaderstats")
		local rank = stats:findFirstChild("Rank")	

	function Update()
	rank.Value = player:GetRoleInGroup(964666)
	while true do wait(5)
	Update()
	end
	end
	end)

It is supposed to update a player's rank when a player joins the server every 5 seconds. "Rank" is a StringValue in leaderstats.

I am not entirely sure what the problem is.

1 comment

0

Very hard to understand what you mean, are you trying to change his rank whenever his rank in the group changes?

1 answer

✓ Accepted answer

TIP: format your code better, E.G:

eventName:connect(function()
	if blah then
		function ye()
			-- code
		end
	end
end)

The problem is that you cannot fire a function inside the same function, change your code to this:

game.Players.PlayerAdded:connect(function(player)
	local stats = player:findFirstChild("leaderstats")
	local rank = stats:findFirstChild("Rank")   
	function Update()
		rank.Value = player:GetRoleInGroup(964666)
	end
	while true do wait(5)
		Update()
	end
end)

EDIT:

It does not wait for stats to exist, so add a new line under Line 1:

repeat wait() until player.leaderstats

Hope I helped :)

~TDP

2 comments

0

00:59:34.783 - Workspace.Leaderboard.Rank:3: attempt to index local 'stats' (a nil value)

0

easy fix, ill edit

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