doesnt update in real time only when player leaves and rejoin (roblox studio)
Archived 2 years ago
A
zain
~~~local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function updateRank(player)
local userId = player.UserId
if ReplicatedStorage.PlayerData[userId] then
local level = ReplicatedStorage.PlayerData[userId].Stats.Level.Value
local rank = "F"
if level >= 85 then
rank = "S+"
elseif level >= 75 then
rank = "S"
elseif level >= 65 then
rank = "A"
elseif level >= 55 then
rank = "B"
elseif level >= 35 then
rank = "C"
elseif level >= 15 then
rank = "D"
end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local rankValue = leaderstats:FindFirstChild("Rank")
if not rankValue then
rankValue = Instance.new("StringValue")
rankValue.Name = "Rank"
rankValue.Parent = leaderstats
end
rankValue.Value = rank
end
end
Players.PlayerAdded:Connect(function(player)
wait(1)
updateRank(player)
for _, existingPlayer in pairs(Players:GetPlayers()) do
updateRank(existingPlayer)
end
end)
ReplicatedStorage.PlayerData.Changed:Connect(function(data)
local userId = data.Name
local playerToUpdate = Players:GetPlayerByUserId(userId)
if playerToUpdate then
updateRank(playerToUpdate)
end
end)~~~
