Can't join two items

Hey Developers, I’m working on a script for my game that teleports a player to a spawn after they press a GUI button via a remote event. But, I couldn’t find a way to address the player model. So I came up with a idea to join game.Workspace to the player name. But, it gives me a error reading “ServerScriptService.InputPlayerScript:7: attempt to concatenate string with Instance”

The script is right here.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("addPlayer")

local Spawns = game.Workspace.Map.CorruptCastle.Spawns:GetChildren()

local function insertPlayer(player)
	local playerValue = "game.Workspace." .. player
	print("game.Workspace" .. player)
	playerValue.CFrame = Spawns[math.random(#Spawns)].CFrame.Position
end

remoteEvent.OnServerEvent:Connect(insertPlayer)

I don’t know what else to do, help is appreciated.

To answer your immediate question, you wouldn’t use a string for the entire path. You’d index the path, like this:

playerValue = game.Workspace[player.Name]

However, in this case, you don’t even need to do that. The Player type has a property Character that will give you what you need.

local function insertPlayer(player)
	local playerValue = player.Character
	playerValue.CFrame = Spawns[math.random(#Spawns)].CFrame.Position
end

Though CFrame is not a property of Model (characters are of the Model type) and you’ll probably see an error for that as well - try using the HumanoidRootPart child of Character instead.

1 Like

Thank you! You’ve saved me a lot of time!