I need to detect changes in a person's role in the group in real time. I have no idea how to do this. This code below checks the rank, however when my group role changed, it receives the old rank and not my new rank screwing it all up. If I was Trainee, if I then change into Supervisor the script still thinks I'm a Trainee. How do I fix this?

function AutoUpdateRank(player)
	wait(1)
	print("ATTEMPT TO LOAD RANK!!!!" .. player.Name)
	while true do
		print("Checking RANK!")
		local newRank = player:GetRoleInGroup(3262436)
		print(player.Name .. "RANK: " .. newRank)
		if player:WaitForChild("leaderstats").Rank.Value ~= newRank then
			print("RANK CHANGED!!!!!")
		end
		player:WaitForChild("leaderstats").Rank.Value = newRank 
		wait(math.random()*10)
	end
end

game.Players.PlayerAdded:Connect(AutoUpdateRank)

for key, player in ipairs(game.Players:GetPlayers()) do
	AutoUpdateRank(player)
end

3 comments

0

You are only firing the AutoUpdateRank when the player joins.

0

You also can't concatenate name. remove the 2 dots after player at line 7 and line 3 and replace it with a ","

0

Yes you can, but using multiple arguments is a lot easier thought