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

String expected, got object? I'll be putting the explorer tree in the post.

Asked by
7z99 203 Moderation Voter
4 years ago
Edited 4 years ago

Hello!

First of all, sorry for the brief title, I wasn't really sure what to make it.

Anyway, I'm not really sure to start so here's the error.

23:36:16.918 - Workspace.GameScripts.PlayerLeft:19: bad argument #2 (string expected, got Object)

Here's the script. If the second last player who is either on the "playing" team, or the "complete" team leaves, "v" in players should be awarded a win. This is just a brief explanation of it. I should also add that the wins object is an IntValue.

01game.Players.PlayerRemoving:Connect(function(plr)
02    local numPlaying = #game.Teams.Playing:GetPlayers()
03    local numComplete = #game.Teams.Complete:GetPlayers()
04    local numLobby = #game.Teams.Lobby:GetPlayers()
05 
06    print(numPlaying.."playing")
07    print(numComplete.."complete")
08    print(numLobby.."lobby")
09    print(plr.Name.."plr")
10    print("player removed")
11 
12    if plr.Team ~= game.Teams.Lobby then
13        if numComplete == 0 then
14            if numPlaying == 1 then
15 
View all 24 lines...

Here's the explorer.

1 answer

Log in to vote
2
Answered by 4 years ago

playing's v in the for loop represents as the player class, use v.Name to extract the certain attribute of the player.

01game.Players.PlayerRemoving:Connect(function(plr)
02    local numPlaying = #game.Teams.Playing:GetPlayers()
03    local numComplete = #game.Teams.Complete:GetPlayers()
04    local numLobby = #game.Teams.Lobby:GetPlayers()
05 
06    print(numPlaying.."playing")
07    print(numComplete.."complete")
08    print(numLobby.."lobby")
09    print(plr.Name.."plr")
10    print("player removed")
11 
12    if plr.Team ~= game.Teams.Lobby then
13        if numComplete == 0 then
14            if numPlaying == 1 then
15 
View all 24 lines...

More details: Wiki>Player.

0
You can also do game.Players[i].leaderstats.Wins.Value = game.Players[i].leaderstats.Wins.Value + 1 to index the players list with the current loop value it's on. killerbrenden 1537 — 4y
0
You need it to be a table, so do game.Players:GetChildren(). LinavolicaDev 570 — 4y
0
Or game.Players:GetPlayers(). youtubemasterWOW 2741 — 4y
0
Yeah. :)) LinavolicaDev 570 — 4y
Ad

Answer this question