Two scripts breaking all the time

Hello, I am working on an obby game and I used a free model for the checkpoints, now I’m starting to wonder if I should replace it… The problem is is that there are two errors in the output breaking parts of the functionality. Heres a picture of the errors:
image

Anyone know whats wrong? Here are the scripts:

Server script in ServerScriptService

local RS = game:GetService("ReplicatedStorage")

repeat wait() until script.Main ~= nil

local main = require(script:WaitForChild("Main")) --Error here

function recived(plr, direction)
	if direction == "up" then
		main.up(plr, direction)
	elseif direction == "down" then
		main.down(plr, direction)
	elseif direction == "up1" then
		main.up10(plr, direction)
	elseif direction == "down10" then
		main.down10(plr, direction)
	elseif plr.leaderstats.Stage.Value > main.TOTAL_STAGES_IN_GAME then
		print("Player is in an older version of the game!")
	end
end

RS.StageTransfer.OnServerEvent:Connect(recived)

Module script inside the Server script:

local trasferHandler = {}

local TOTAL_STAGES_IN_GAME = 0

for _, stage in pairs(workspace.Checkpoints:GetChildren()) do
	if tonumber(stage.Name) > TOTAL_STAGES_IN_GAME then --Error here
		TOTAL_STAGES_IN_GAME = tonumber(stage.Name)
	end
end

function trasferHandler.up(plr, direction)
	local tpStage = plr.TeleportedStage
	if tpStage.Value < plr.leaderstats.Stage.Value then
		tpStage.Value += 1
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.TeleportedStage.Value].CFrame + Vector3.new(0,3.25,0)
	elseif tpStage.Value == plr.leaderstats.Stage.Value then
		tpStage.Value = 0
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints["0"].CFrame + Vector3.new(0,3.25,0)
	end
end


function trasferHandler.down(plr, direction)
	local tpStage = plr.TeleportedStage
	if tpStage.Value > 0 then
		tpStage.Value -= 1
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[tpStage.Value].CFrame + Vector3.new(0,3.25,0)
	elseif tpStage.Value == 0 then
		tpStage.Value = plr.leaderstats.Stage.Value
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.leaderstats.Stage.Value].CFrame + Vector3.new(0,3.25,0)
	end
end


function trasferHandler.up10(plr, direction)
	local tpStage = plr.TeleportedStage
	if tpStage.Value + 9 < plr.leaderstats.Stage.Value then
		tpStage.Value += 10
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.TeleportedStage.Value].CFrame + Vector3.new(0,3.25,0)
	elseif tpStage.Value == plr.leaderstats.Stage.Value then
		tpStage.Value = 0
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints["0"].CFrame + Vector3.new(0,3.25,0)
	end
end


function trasferHandler.down10(plr, direction)
	local tpStage = plr.TeleportedStage
	if tpStage.Value > 9 then
		tpStage.Value -= 10
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[tpStage.Value].CFrame + Vector3.new(0,3.25,0)
	elseif tpStage.Value == 0 then
		tpStage.Value = plr.leaderstats.Stage.Value
		plr.Character.HumanoidRootPart.CFrame = workspace.Checkpoints[plr.leaderstats.Stage.Value].CFrame + Vector3.new(0,3.25,0)
	end
end



return trasferHandler


Says you are trying to conpare number > nil, can you show where this line is?

image

Could be since TOTAL_STAGES_IN_GAME being 0, not sure, ill brb

1 Like

It says:
image
number < nil
And no, 0 is not nil. It is still an int value.

@Earthraphobic2
The problem is that you’re probably converting a string (with characters inside it) into a number, which is pretty much impossible. Try using string.sub() to get the number out of it. There’s also plenty of other string maniplation options to get the number inside the stage name.

1 Like

Just realized in checkpoints folder there was a part in there which was named “CasualSection” which is why it was giving an error. I am so sorry for wasting your time D:

1 Like

It’s nothing really lol. I’ve had to deal with worse. Just remember this next time you have an odd one out in your folders!

1 Like

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