Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fix "this"? (IDK how to explain in one sentences)

I have errors using a (some scripts but the error is in this one script) script that is originated from YouTube and then modified. I don't know if the modification did this error tho, since I didn't really edit the line that has the error. Error: 'ServerScriptService.ChatGUIServerScript:6: attempt to concatenate upvalue 'connectedPlayer' (a userdata value)' Script Type: Script Code:

local ChatStorage = game.ServerStorage.ChatStorage
game.Players.PlayerAdded:connect(function(connectedPlayer)
	connectedPlayer.Chatted:connect(function(sendMessage)
		local messageValue = Instance.new('StringValue', ChatStorage)
		messageValue.name = connectedPlayer..': '..sendMessage
		local replicatedMessage = messageValue:Clone()
		replicatedMessage.Parent = game.ReplicatedStorage.ClientChatStorage
	    local ClientChatCtorage = replicatedMessage.Parent
	end)
end)

I could link the video, but but its your choice. And I'm bad at LUA so expect me to not understand stuff. Anddddd I'm new here.

1 answer

✓ Accepted answer

The problem is that "connectedPlayer" is the player object and not a string so you cannot concatenate an object.

game.Players.PlayerAdded:connect(function(connectedPlayer)
    connectedPlayer.Chatted:connect(function(sendMessage)
        print( connectedPlayer..': '..sendMessage)
    end)
end)

I'm guessing that you want the players name which is a property of the player object, it is also a string.

game.Players.PlayerAdded:connect(function(connectedPlayer)
    connectedPlayer.Chatted:connect(function(sendMessage)
        print( connectedPlayer.Name..': '..sendMessage)
    end)
end)

Hope this helps, please also check the wiki Lua_errors and look at the events you are using to understand what is passed as a parameter.

This discussion is preserved as it was. New answers, comments, and votes are closed.