Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I fix the error: Character is not a valid member of SpawnLocation?

I'm trying to make a round system in one of my games and I've been having this problem for hours. Line 15 or "local char = player.Character" is what I'm having trouble with. It says "Character is not a valid member of SpawnLocation". Any ideas?

-- Round Variables
local roundLength = 300
local intermissionLength = 20
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn


InRound.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
		end
	end		
end)



local function roundTimer()
	while wait() do
		for i = intermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength, 1, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left !"
		end
	end
end

spawn(roundTimer)

1 answer

Hello.

Solution:

Use Players:GetPlayers() instead of Players:GetChildren().

Fixed Code:

-- Round Variables
local roundLength = 300
local intermissionLength = 20
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn


InRound.Changed:Connect(function()
    wait(1)
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetPlayers()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
        end
    else
        for _, player in pairs(game.Players:GetPlayers()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
        end
    end     
end)



local function roundTimer()
    while wait() do
        for i = intermissionLength, 1, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "Intermission: ".. i .." seconds left!"
        end
        for i = roundLength, 1, -1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game: ".. i .." seconds left !"
        end
    end
end

spawn(roundTimer)

This discussion is preserved as it was. New answers, comments, and votes are closed.