I got this error: SpawnLocation1 is not a valid member of Workspace "Workspace" - Client - SpawnScript:2

Here is my local script named SpawnScript:

local player = game:GetService('Players').LocalPlayer
player.RespawnLocation = game.Workspace.SpawnLocation1
game.StarterGui.ScreenGui.TextLabel.Text = player.RespawnLocation.Name

I tried putting it in ReplicatedFirst.

I tried putting it in StarterPlayerScripts.

Neither of these worked, as I got this error every time:

SpawnLocation1 is not a valid member of Workspace “Workspace” - Client - SpawnScript:2

By the way, I don’t mean to RickRoll you with my shirt. This post is legitimate. This is not a troll.

I appreciate any help I can get.

3 Likes

Use WaitForChild; at the time the script runs, the Instance hasn’t been replicated to the client yet.

local player = game:GetService('Players').LocalPlayer
player.RespawnLocation = workspace:WaitForChild("SpawnLocation1")

-- When showing something on the player's screen, use PlayerGui, not StarterGui.
local screenGui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
screenGui.TextLabel.Text = player.RespawnLocation.Name
2 Likes

Local scriprs run as soon as the player joins, before the things in workspace are replicated. Like the player said above me use :WaitForChild() so it ensures the part is loaded before proceeding.

Your new code:

local spawnLocation = workspace:WaitForChild("SpawnLocation2")
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.