Hey guys. I’m currently making a obby that doesn’t use checkpoints that use leaderstats. Whenever I spawn in with this, the checkpoints work, but my character is invisible. Here is what I’ve been using:
game.Players.PlayerAdded:Connect(function(player)
local value = Instance.new(“NumberValue”,player)
value.Name = “Checkpoint”
value.Value = 0
local function SetCheckpoint(player,v)
if tonumber(string.sub(v.Name,6,100000)) > player.Checkpoint.Value then
player.Checkpoint.Value = tonumber(string.sub(v.Name,6,100000))
print(player.Name…" reached Checkpoint “…tonumber(string.sub(v.Name,6,100000))…”!")
end
end
for i,v in pairs(workspace.Levels:GetChildren()) do
if v.ClassName == “Part” then
v.Touched:Connect(function(object)
SetCheckpoint(game.Players:GetPlayerFromCharacter(object.Parent),v)
end)
end
end
If anyone could assist me with fixing this, it would be greatly appreciated. Also sorry for the formatting, I couldn’t get the script to copy/paste correctly.
game.Players.PlayerAdded:Connect(function(player)
local value = Instance.new(“NumberValue”,player)
value.Name = “Checkpoint”
value.Value = 0
player.CharacterAdded:Connect(function(character)
wait(1)
character.HumanoidRootPart.Position = workspace.Levels[“Level”…player.Checkpoint.Value].Position + Vector3.new(0,5,0)
end)
end)
local function SetCheckpoint(player,v)
if tonumber(string.sub(v.Name,6,100000)) > player.Checkpoint.Value then
player.Checkpoint.Value = tonumber(string.sub(v.Name,6,100000))
print(player.Name.." reached Checkpoint " ..tonumber(string.sub(v.Name,6,100000)).."!")
end
end
for i,v in pairs(workspace.Levels:GetChildren()) do
if v.ClassName == “Part” then
v.Touched:Connect(function(object)
SetCheckpoint(game.Players:GetPlayerFromCharacter(object.Parent),v)
end)
end
end
SetCheckpoint will fire many times when the player touches the part because many parts of the player can touch the part, and it will also fire if other parts touch the player.
You should do
v.Touched:Connect(function(object)
local player = game.Players:GetPlayerFromCharacter(object.Parent)
if player then
SetCheckpoint(player,v)
end
end)
You might also want to add a debounce so it doesnt fire many times over
secondly
if tonumber(string.sub(v.Name,6,100000)) > player.Checkpoint.Value then
player.Checkpoint.Value = tonumber(string.sub(v.Name,6,100000))
print(player.Name.." reached Checkpoint " ..tonumber(string.sub(v.Name,6,100000)).."!")
end
that’s a very interesting way of getting the checkpoint, I would put an Attribute in the checkpoint with the number that it is