Attempt to call a nil value

`Hello Devs,

 I am trying to make a round system for my game based of the tutorial gnomecode did for his game "teddy" but whenever I try to run the game I get an error in my script of "attempting to call a nil value". I have looked everywhere online but have found nothing to help me fix this problem. I bet that this is a simple fix I just don't understand how to fix it.`

Here is my code from the main server script:

local function intermission()
	playerModule.respawnAllPlayers()
	roundModule.Countdown("Intermission", 5)
end

local function startGame()
	playerModule.teleportAllPlayers()
	roundModule.Countdown("Game", 3)
end

while true do
	intermission()
	startGame()
end

Here is my module script code:

local playerModule = {}

local roundInfo = game.ReplicatedStorage:WaitForChild("RoundInfo")

game.Players.PlayerAdded:Connect(function(player)
	local marker = Instance.new("StringValue", roundInfo.Players)
	marker.Name = player.Name
end)

function playerModule.teleportPlayer(playerName, location)
	local gamePlayer = game.Players:FindFirstChild(playerName)
	if gamePlayer then
		local character = workspace:FindFirstChild(playerName)
		if character then
			character:WaitForChild("HumanoidRootPart").CFrame = location.CFrame
			character.HumanoidRootPart.CFrame = location.CFrame
	end
end

function playerModule.teleportAllPlayers(location)
	for index, player in pairs(roundInfo.Players:GetChildren()) do
		playerModule.teleportPlayer(player.Name, location)
		end
	end
end

function playerModule.respawnAllPlayers() 
	for index, player in pairs(roundInfo.Players:GetChildren()) do
		local gamePlayer = game.Players:FindFirstChild(player.Name)
		if gamePlayer then
			gamePlayer:LoadCharacter()
		end
	end
end

return playerModule

Potentially because you have a ‘end’ below ‘playerModule.teleportPlayer(player.Name, location)’ inside of ‘function playerModule.teleportAllPlayers(location).’ As well as you are missing an ‘end’ inside of ‘function playerModule.teleportPlayer(playerName, location)’ below ‘character.HumanoidRootPart.CFrame = location.CFrame’

I’d attempt that first, as it appears you took if character and removed it from the function. I’d also attempt adding a task.wait() or a wait() inside of your while true loop. The reason why the wait should be added can be found here.

Still getting the same error in output even after cleaning up the scripts

Can you get a screenshot of the error for me?

With that as well can you place some print(“step completed”)'s inside of your functions so we can debug it and find the point of failure?

here is an image of the error
roblox error

What is at line 43 inside of the Server script located in ServerScriptService?

the line that calls my module script

playerModule.teleportAllPlayers(workspace.Spawn)

Place inside of that function a few prints (i.e print(location) print(index,player) )

This should allow us to see exactly what is nil

It doesnt even seem to be running the function because nothing shows up in the output if I try to print out what the teleport location is

Question, so when you call;

local function startGame()
	playerModule.teleportAllPlayers()
	roundModule.Countdown("Game", 3)
end

You never added a location inside of teleportAllPlayers(). Is that still true? If so, you’ll need a location added as a argument.

i have a location in there yes, my mistake for not including that in my code in this post

Are you able to provide me with a more in-depth screenshot or code of what your code looks like from top to where the issues are at?

here is my full server side code, I am trying to recreate the Melon Race gamemode from Gmod

--services
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

--varibles
local Melon = game.ReplicatedStorage.Assets.Melon:WaitForChild("character")

local roundInfo = game.ReplicatedStorage.RoundInfo

local roundModule = require(game.ReplicatedStorage.Modules.Round)
local playerModule = require(game.ReplicatedStorage.Modules.Player)

--setting up player
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local rootPart = character:WaitForChild("HumanoidRootPart")
		local humanoid = character:WaitForChild("Humanoid")	
		
		local playerMelon = Melon:Clone()
		
		playerMelon.Parent = character
		
		local Weld = Instance.new("Weld")
		Weld.Parent = playerMelon
		Weld.Part0 = rootPart
		Weld.Part1 = playerMelon
		
		humanoid.PlatformStand = true
		
		humanoid.Died:Connect(function()
			humanoid.PlatformStand = false
			end)
		end)
	end)

--game logic(round system)
local function intermission()
	playerModule.respawnAllPlayers()
	roundModule.Countdown("Intermission", 5)
end

local function startGame()
	playerModule.teleportAllPlayers(workspace.Spawn)
	roundModule.Countdown("Game", 3)
end

while true do
	intermission()
	startGame()
	task.wait()
end

put .Position on the workspace.Spawn?

I’m using CFrames for the teleporting

then put CFrame instead of Position

I did it doesn’t work still get the same error

There could be a few reasons; however, since it is calling nil on a value I have reason to believe the moduleScript is erroring out somehow. Im going to review it again rq

Alright, lets try a few options I have in mind,

take,

local marker = Instance.new("StringValue", roundInfo.Players)
marker.Name = player.Name

and place it inside of the ‘Server’ script and remove the PlayerAdded from your module. This will work because you are already calling PlayerAdded inside of the Server script

Add a print(“module is working”,roundInfo) AFTER the roundInfo.

Lets see what occurs

I am still getting the same error