Unable to assign property RespawnLocation. Object expected, got string

Hello I ran to this problem with this script, I keep getting this error. What im trying to do is basically make the player spawn at a certain place.

Module Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Teams = game:GetService("Teams")
local PlayerManager = require(ServerScriptService.Data.PlayerManager)

local spawnLocations = game.Workspace.JobSpawns
local Shack = {}

Shack.__index = Shack

function Shack.New(Player)
	
	local self = setmetatable({}, Shack)
	
	self.Employee = Player
	self.Job = Player.Team
	
	return self
	
end

function Shack:jobSpawns(jobLocation)

	local fVar = ""
	local Data = {

		["1"] = spawnLocations.Manager,
		["2"] = spawnLocations["Assistant Manager"],
		["3"] = spawnLocations.Supervisor,
		["4"] = spawnLocations.Chef,
		["5"] = spawnLocations.Janitor,
		["6"] = spawnLocations.Cashier,

	}

	if jobLocation == "Manager" then
		fVar = Data["1"]
	end

	if jobLocation == "Assistant Manager" then
		fVar = Data["2"]
	end

	if jobLocation == "Supervisor" then
		fVar = Data["3"]
	end

	if jobLocation == "Chef" then
		fVar = Data["4"]
	end

	if jobLocation == "Janitor" then
		fVar = Data["5"]
	end

	if jobLocation == "Cashier" then
		fVar = Data["6"]
	end
	return (fVar)
end


function Shack:Init()
	
	local Job = self:jobSpawns(self.Job)
	self.Employee.RespawnLocation = Job
	self:LoadCharacter()
	
end

return Shack
1 Like

You assigned fVar to an empty string instead of an object. When you can’t find a spawn location then it results in a string, which results in the error:

	local fVar = ""

Try replacing this with the following:

	local fVar = nil

The error is now gone but the object is apperently nil. I added a print line,

	local Job = self:jobSpawns(self.Job)
	print(Job)

The output prints out nil.

Fixed problem! Thanks for the help with the error