Why isnt this checkpoint system working?

local num = tonumber(script.Parent.Parent.Name)
script.Parent.SurfaceGui.TextLabel.Text = "LEVEL: ".. math.ceil(num*1.5)
local spawn = script.Parent
spawn.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		if game.Players[hit.Parent.Name].leaderstats.Level.Value >= math.ceil(num*1.5) then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Model", game.ServerStorage)
			checkpointData.Name = "CheckpointData"
		end
		local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
		if not checkpoint then
			checkpoint = Instance.new("ObjectValue", checkpointData)
			checkpoint.Name = tostring(player.userId)
			player.CharacterAdded:connect(function(character)
				wait()
				character:WaitForChild("Torso").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
			end)
		end
		checkpoint.Value = spawn
		else
			local human = hit.Parent:FindFirstChild("Humanoid") 
			human.Health = 0
			game.Players[hit.Parent.Name].PlayerGui.enough.Enabled = false
			game.Players[hit.Parent.Name].PlayerGui.enough.Enabled = true
			game.Players[hit.Parent.Name].PlayerGui.enough.Frame.TextLabel.Text = "Hey ".. hit.Parent.Name.. "! You need to be level "..math.ceil(num*1.5).. " to be able to play this obby, play and finish more obbies to level up."
			wait(5)
			game.Players[hit.Parent.Name].PlayerGui.enough.Enabled = false	
		end
	end
end)

Short and simple, its not working. Found this system off of toolbox so maybe that’s it? Its probably something I added in that makes it not work, but i don’t know what, no output errors. I have tried to print to see if it finds the humanoid and it does, but I am not sure why it doesn’t work.

1 Like

re-wrote it

local spawn = script.Parent
local num = tonumber(script.Parent.Parent.Name)
script.Parent.SurfaceGui.TextLabel.Text = "LEVEL: ".. math.ceil(num*1.5)
spawn.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		if game.Players[hit.Parent.Name].leaderstats.Level.Value >= math.ceil(num*1.5) then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
			if not checkpointData then
				checkpointData = Instance.new("Model", game.ServerStorage)
				checkpointData.Name = "CheckpointData"
			end

			local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
			if not checkpoint then
				checkpoint = Instance.new("ObjectValue", checkpointData)
				checkpoint.Name = tostring(player.userId)

				player.CharacterAdded:connect(function(character)
					wait()
					character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
				end)
			end

			checkpoint.Value = spawn
		else
			local human = hit.Parent:FindFirstChild("Humanoid") 
			human.Health = 0
			game.Players[hit.Parent.Name].PlayerGui.enough.Enabled = false
			game.Players[hit.Parent.Name].PlayerGui.enough.Enabled = true
			game.Players[hit.Parent.Name].PlayerGui.enough.Frame.TextLabel.Text = "Hey ".. hit.Parent.Name.. "! You need to be level "..math.ceil(num*1.5).. " to be able to play this obby, play and finish more obbies to level up."
		end
	end
end)