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

attempt to concatenate table with string?

Asked by
Talveka 31
4 years ago
Edited 4 years ago

hello! i am having trouble with a specific function. i've verified that everything else works, it's just this part of the minigame handler i am currently working on. i'm calling the function each time a player leaves or dies in a round, verifying that it updates.

"inround" is a table im adding and removing players to, in order to manage a round.

server script;

local win = repstr:WaitForChild("PlayerWin")

function findwin()
    if #inround == 1 then
    print(unpack(inround)) -- for checking
    win:FireAllClients(inround, 1)
    end
end

local script;

local hintbar = script.Parent.ScreenGui.TextLabel


game.ReplicatedStorage.PlayerWin.OnClientEvent:Connect(function(inround)
    hintbar.Text = inround.. " has won the round!"
end)

the error is on this line;

hintbar.Text = inround.. " has won the round!"

specifically, it says "attempt to concatenate table with string". any help would be greatly appreciated!

2 answers

Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago
Edited 4 years ago

The problem is, that inround value is a table. You have to convert it to a string. You can do this to fix the problem

inround[Player]
local hintbar = script.Parent.ScreenGui.TextLabel

game.ReplicatedStorage.PlayerWin.OnClientEvent:Connect(function(Player)
    hintbar.Text = (Player.." has won the round!")
end)
0
tried applying the edits you did, it resorted to telling me about an "incorrect statement". is there any other way i can convert a table to a string? Talveka 31 — 4y
0
Table[string] iuclds 720 — 4y
0
after a bit of tinkering, i got your solution to work! thank you! Talveka 31 — 4y
Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

inround still remains an Array, you’re essentially trying to mend an Object to a string, which is causing controversy. To attain a properly extract and format a string of all the "contestants" within the array, you can use the table.concat() function, and pass the separation argument with a whitespace.

local Text = table.concat(Array, ' ').." has won the game!"
0
ive now made those edits, but i've gotten another error which is "invalid value (userdata) at index 1 in table for 'concat'". the edited line now is "hintbar.Text = table.concat(inround, ' ').." has won the game!"" Talveka 31 — 4y

Answer this question