Error: invalid argument #2 (string expected, got Instance)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to place a surface gui on a player’s head when a gui button is pressed.

  2. What is the issue? Include screenshots / videos if possible!
    I am clicking the enter button and the remote executes properly but does not parent the surfacegui to the player’s head

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have gone through every topic similar to this but to no avail.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Username")

local function onReady(Username, AT)
	local newClone = game.ReplicatedStorage.UsernameGUI:Clone()
	newClone.Parent = workspace[Username].Head


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

How are you setting the parameters of the function?

The first parameter of OnServerEvent is the player who fired the event, so Username is the Player instance who fired the event, and AT is the parameter given when you give an argument in FireServer

You can get the character via Username.Character instead of getting it from the workspace, this can also help in the event the character doesn’t exist by the time the event was fired, so you can check that

local function onReady(player, AT)
	if not player.Character then
	local newClone = game.ReplicatedStorage.UsernameGUI:Clone()
	newClone.Parent = player.Character.Head

Edit: Just to include, do not fire in the player instance yourself in the FireServer, just fire in the other arguments


The parameters are being set through a client sided GUI with a text box and submit button.

1 Like