Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

how would i get the players name without it being blank? (server script)

Asked by 5 years ago
Edited 5 years ago

so i have a function with returns a string for a message to be put out when the game ends but i just dont know how to get the username of the player. (thing with elseif gamemode==2 then)

function (the lines i wanna focus on are 22-28)

01function getWinningTeamString()
02    local red = 0
03    local blue = 0
04 
05    local players = game.Players:GetChildren()
06    local a = 0
07 
08if gamemode == 1 then
09    for i=1,#players do
10        if (players[i].TeamColor == game.Teams:FindFirstChild("BLUE TEAM").TeamColor) then
11            if (players[i]:FindFirstChild("leaderstats") and players[i].leaderstats:FindFirstChild("Kills")) then
12                blue = blue + players[i].leaderstats:FindFirstChild("Kills").Value
13            end
14        end
15 
View all 39 lines...

where this function is used is here (line 14):

01while true do
02    players = game:GetService("Players"):GetChildren()
03    repeat wait(1) do end until #players>=2
04        gamemode = 2--math.random(1,2)
05    if gamemode==1 then
06        gamestart(mapstorage.TDM:GetChildren())
07    elseif gamemode==2 then
08        gamestart(mapstorage.FFA:GetChildren())
09    end
10    wait(game_length-30)
11        messageEvent:FireAllClients("30 seconds left until the end of this round!",5)
12        script["30seconds"]:Play()
13    wait(30)
14        messageEvent:FireAllClients(getWinningTeamString(),30) -- right here btw
15-- i cut off the rest since theres no point in displaying it

1 answer

Log in to vote
1
Answered by 5 years ago

What you need to do is index the player in your for loop, and then index its properties.

1local Players = game:GetService("Players"):GetPlayers()
2 
3for i = 1, #Players do
4    local plr = Players[i]
5    local leaderstats = plr:FindFirstChild("leaderstats")
6    if leaderstats then
7        local kills = leaderstats:FindFirstChild("Kills")
8    end
9end

All you will need to do to index the player's name is plr.Name.

0
thanks bro speedyfox66 237 — 5y
Ad

Answer this question