How to assign a value to a player when join

How do I assign a value between 1 - 6 to players when they join? (server size is 6). I already made a folder that have a intvalue inside for storing the value, but how can i pass out the value? the value cannot repeat among players in the same server, what should i do?

game:GetService("Players").PlayerAdded:Connect(function(plyr)
    plyr:SetAttribute("value", math.random(1, 6))
end)

for k, v in pairs(game:GetService("Players"):GetChildren()) do
    print(v:GetAttribute("value"))
end

You’re asking a lot of questions today - are you Googling before posting?

1 Like

IntValue.Value = #game:GetService("Players"):GetPlayers() + 1

yeah i do googling before, but just I am not being able to find the suitable code for me

back to the code, how can i asure that the number of the players wont be the same with ur code

Using an equality check.

.PlayerAdded ...
    local val = math.random(1, 6)
    for k, v in pairs(game:GetService("Players"):GetChildren()) do
        -- set attribute
        -- append attribute to table
        -- check if attribute is already in table
        -- if true, regenerate attribute and check again
    end
end)
2 Likes

im new to roblox lua, how do you set an attribute with code?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.