#description won't apply

1 messages · Page 1 of 1 (latest)

summer stag
#

i don't know why but it just says that player that is selected is a nil
client (local script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:FindFirstChild("Events")
local player = Players.LocalPlayer
local function GetPlayerCount()
    local PlayerList = Players:GetPlayers()
    return #PlayerList
end
local function WriteText()
    for i=0,5,1 do
        if GetPlayerCount() <= 1 then
            script.Parent.Text = "Starting in "..5-i
            task.wait(1)
        end

    end
end
WriteText()
events:FindFirstChild("SkinLoaderManager"):FireServer()

server (script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:FindFirstChild("Events")

task.wait(3)
local playerList = players:GetPlayers()


print(#playerList)

local function GetRandomPlayer()
    local playerList = players:GetPlayers()

    if #playerList <= 1 then
        return nil 
    end

    
    local randomIndex = math.random(1, #playerList)
    return playerList[randomIndex]
end


events:FindFirstChild("SkinLoaderManager").OnServerEvent:Connect(function()
    local randomPlayer = GetRandomPlayer()
    local noob = game.Workspace:FindFirstChild("Noob")
    local description = players:GetHumanoidDescriptionFromUserIdAsync(randomPlayer.UserId)
    noob:WaitForChild("Humanoid"):ApplyDescriptionAsync(description)
end)

description just won't apply help

brittle anvil
summer stag
brittle anvil
#

oh wait, i think i figured it out

if #playerList <= 1 then
  return nil 
end

the reason why the player is nil, is because the function that gets the player returns nil.
this happens to you because you're mostly testing the game solo, which will result in a playerList containing just you.
to fix this, simply remove that part of the function. It will still return the player nonetheless, because the randomIndex would always be 1 anyway

brittle anvil
#

np

summer stag
# brittle anvil np

yooooo it actually worked you fixed like 2 days of work ngl thank you very much again