Attempt to index nil with 'SpawnPart'

I have made a script that once an event has fired, the player is teleported to a model. It only seems to work for the person who made the spawn position (I’m making a flag place and spawn system), perhaps because of this "attempt to index nil with ‘SpawnPart’ (The part I want to teleport the player to). I tried a waitforchild() before but it would just time out waiting for it. This is in ServerScriptService by the way.

game.ReplicatedStorage.FlagSpawn.TeleportPlayer.OnServerEvent:Connect(function(Player, Owner)
	local Character = Player.Character
	local Flag = game.Workspace.SpawnedProps:FindFirstChild(Owner.Name)
	local HRP = Character:WaitForChild("HumanoidRootPart")
	HRP.Position = Flag.SpawnPart.Position

Here is a screenshot of the game explorer what it looks like:

I’m assuming that the player has some sort of tool that allows them to create a remote spawn location for team mates to also spawn at.

The reason this doesn’t work is because if the player makes a spawn location on their client, without relaying this to the server, then only the client that made it will be able to see it. It basically doesn’t exist on the server, thus it doesn’t exist for any other client.

If this is the case, and assuming you’re not using remotes, I suggest you read this article about using them:
Remote Functions and Events

The article provides a few examples on how to use remotes.

(if this isn’t the problem, and if you are using remotes, I suggest you elaborate on your issue a little more)

The spawn location is created on the server so all the players can see it. They can also see the spawn button created in the GUI. It’s just for some reason it’s not allowing them to teleport to it. Would it be more helpful if I provided all the scripts involved in this system I made?

Show me the code that relates to placing the spawn point. I think that’s where the problem is located.

Alright, I will do. Here is proof that the flag is visible for everyone. I tested with 2 players placing their flags down in studio:


And here is the flag placing script. This is supposed to place the flag where the player wants and get it ready to be teleported to.

local spawnevent = game.ReplicatedStorage.Tools.PlaceFlag

function spawnflag(player,objectname,placepos)
	local flag = game.ServerStorage:FindFirstChild(objectname)
	if flag ~= nil then
		local clone = flag:Clone()
		if game.Workspace.SpawnedProps:FindFirstChild(player.Name) then
			clone.Name = (player.Name)
			clone.Owner.Value = (player.Name)
			clone.Parent = game.Workspace.SpawnedProps
			local creator = player
			clone:SetPrimaryPartCFrame(placepos +,1,0))
			local Model = clone:GetChildren()


			for i,v in pairs(Model) do
				if v:IsA("BasePart") then
					v.Anchored = true


Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace= game:GetService("Workspace")

ReplicatedStorage.FlagSpawn.TeleportPlayer.OnServerEvent:Connect(function(Player, Owner)
	local Character = Player.Character
	local Flag = Workspace.SpawnedProps:FindFirstChild(Owner.Name)

	if not Flag then return end
	local HRP = Character:WaitForChild("HumanoidRootPart")
	HRP.Position = Flag.SpawnPart.Position

Does it still error?
Is the error different?
Does it teleport the player?

(wrote this on DevForum so excuse any typos)

It’s still not working. Only the person who put down the flag can spawn there.