Script Error please help

So my here’s my problem i have been watching some scripting tutorials and i decided to make a checkpoint but my script isn’t working this is what i get in my output
(Workspace.Checkpoint.Checkpoint:20: attempt to call a nil value)
heres my script
‘’’
—local checkpoint = script.Parent

function stepOnCheckpoint(part)

-- check If its a player that stepped on the checkpoint
if part.Parent and part.Parent:FindFirstChild('Humanoid') then
	
	--picks the right player
	local player = game.Players:GetPlayerFromCharacter(part.Parent)		
	--get the saved checkpoint data
	local CheckpointData = game.ServerStorage:FindFirstChild('CheckpointData')
	--creates the checkpoint data because its not a library item
	if not CheckpointData then
		--Create the checkpoint data
		CheckpointData = Instance.new("Model", game.ServerStorage)
		CheckpointData = 'CheckpointData'
	end
	
	--get the player's saved checkpoints
	local savedCheckpoint = CheckpointData:FindFirstChild(player.Name)
	--Check if the player has no saved checkpoints
	if not savedCheckpoint then
		-- create the players saved checkpoint data
		savedCheckpoint = Instance.new('ObjectValue', CheckpointData)
		savedCheckpoint.Name = player.Name
		
		--Tell the player to respawn at that checkpoint
		function goTocheckpoint()
			wait()
			--get the respawn location
			local location = savedCheckpoint.Value.CFrame 
			--move the character there
			character:WaitForChild('HumanoidRootPart').CFrame = location + vector3.new(0,4,0)
		end
		player.CharacterAdded:Connect(goTocheckpoint)
	end
	savedCheckpoint.value = checkpoint
	
end

end
checkpoint.Touched:Connect(stepOnCheckpoint)
‘’’

1 Like
CheckpointData = 'CheckpointData'

This line seems to be the cause of it, did you forget to add .Name?

CheckpointData.Name = 'CheckpointData'

Least I think it is that, but that’s one of the first things I saw

That’s probably it let me try it
wait what line is this on i used it more then once oh i see thanks

Your basically setting a instance variable to a string, you’ll need to add a .Name

it didnt work do you see any other problems?

Okay let’s trouble shoot a bit, add some prints for the name of the player and for CheckPointData

print(CheckpointData.Name)
print(player.Name)
--get the player's saved checkpoints
		local savedCheckpoint = CheckpointData:FindFirstChild(player.Name)

It’s one of those that’s causing it

already fixed that part thanks tho

Found it out the error is on line 29 just have to find the error now
another error on 34 too

Okay wait show me an image of what you’re seeing that’s erroring

You forgot to define character.

its character it says its unkown

Okay yea you didn’t define charact,er, change this

function goTocheckpoint()

To this

function goTocheckpoint(character)

Hm fixed it it still doesnt work

Are you getting anymore red lines?

No but i got a error now Workspace.Checkpoint.Checkpoint:32: attempt to index nil with ‘CFrame’ -

There’s no chance it can be nil though as he does set it at the end to the checkpoint, it could be that he forgot to capitalize Value, as he wrote savedCheckpoint.value = checkpoint

Oh just realized that I missread the code.

Hmm let me check if i get anymore errors

This out, it should have all the fixes mentioned

local checkpoint = script.Parent

function stepOnCheckpoint(part)

	-- check If its a player that stepped on the checkpoint
	if part.Parent and part.Parent:FindFirstChild('Humanoid') then
		
		--picks the right player
		local player = game.Players:GetPlayerFromCharacter(part.Parent)		
		--get the saved checkpoint data
		local CheckpointData = game.ServerStorage:FindFirstChild('CheckpointData')
		--creates the checkpoint data because its not a library item
		if not CheckpointData then
			--Create the checkpoint data
			CheckpointData = Instance.new("Model", game.ServerStorage)
			CheckpointData.Name = 'CheckpointData'
		end
		
		--get the player's saved checkpoints
		local savedCheckpoint = CheckpointData:FindFirstChild(player.Name)
		--Check if the player has no saved checkpoints
		if not savedCheckpoint then
			-- create the players saved checkpoint data
			savedCheckpoint = Instance.new('ObjectValue', CheckpointData)
			savedCheckpoint.Name = player.Name
			
			--Tell the player to respawn at that checkpoint
			function goTocheckpoint(character)
				wait()
				--get the respawn location
				local location = savedCheckpoint.Value.CFrame 
				--move the character there
				character:WaitForChild('HumanoidRootPart').CFrame = location + vector3.new(0,4,0)
			end
			player.CharacterAdded:Connect(goTocheckpoint)
		end
		savedCheckpoint.Value = checkpoint
		
	end
end
checkpoint.Touched:Connect(stepOnCheckpoint)

Thanks but still not working
not sure why
wait new error Workspace.Checkpoint.Checkpoint:1: Expected identifier when parsing expression, got Unicode character U+2014