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)
‘’’
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
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