So i got this PlayerChatted Event, tostring() "error" and here is my script,

Script:

local recipient = ""
	
game.Players.PlayerAdded:Connect(function(player)
	Mic.ClickDetector.MouseClick:Connect(function()
		workspace.Mic:WaitForChild("StringValue").Value = player.Name
		player.Chatted:Connect(function(message)
		
			recipient = workspace.Mic:WaitForChild("StringValue").Value -- the StringValue.Value will change to the player's name when the player clicked workspace.Mic	
		
			workspace.Mic.BillboardGui:WaitForChild("TextLabel").Text = "["..player.Name.."]: "..tostring(recipient[message]) -- "Error" tostring(recipient[message])
		
		end)
	end)
end)

IMPORTANT

Note that this is not the full script but i got the error from my print() function, i mean it has no error but its not what i expected it to be so i call it "Error".

Error Line: ..tostring(recipient[message])

Output for the TextLabel.Text: [Yokohane]: nil -- "Yokohane" is just an example :)


Any Helps Will Be Greatly Appreciated.

Will Accept The Most Suitable Answer.

9 comments

0

Questions with "URGENT" in the title are bad questions.

0

recipient's set up as a string, yet you're trying to index it as if it's a table. >-<

0

^ What TheeDeathCaster said. recipient[message] doesn't make any sense because recipient is a string, and Lua doesn't support indexing strings.

0

Technically you can index strings, like str:reverse() would still be indexing

0

@incapaxian ok so?? its still qn lol and how is it a bad qn? why are u assuming that qn with 'URGENT' are bad qns?

0

@TheeDeathCaster how do i do it?

0

@fredfishy uhh i dont understand as i dont really write a script like this. can u explain it to me?

0

You don't index it as a table?

0

@TheeDeathCaster What do i index it as?? String?? But how to index sting tho??