I’m having a couple problems with my checkpoint system, and I don’t know how to solve them. Here are my scripts:
ServerScriptService:
local Players = game:GetService("Players")
local chekpointsFolder = game.Workspace.Checkpoints
Players.PlayerAdded:Connect(function(plr)
local checkpoints = Instance.new("Folder")
checkpoints.Name = "Checkpoints"
checkpoints.Parent = plr
local current = Instance.new("StringValue")
current.Parent = checkpoints
current.Name = "Current"
plr.CharacterAdded:Connect(function(char)
if current.Value ~= nil then
local point = chekpointsFolder:FindFirstChild(current.Value)
char:MoveTo(point.Position)
end
end)
end)
In the checkpoint:
local checkpoint = script.Parent
local Players = game:GetService("Players")
checkpoint.Touched:Connect(function(part)
local character = part.Parent
local plr = Players:GetPlayerFromCharacter(character)
local points = plr.Checkpoints
local current = points.Current
current.Value = checkpoint.Name
end)
The first thing is that it won’t change the player’s position, and they spawn back at the start. The second issue is that I want to use collection service, but I don’t know how to do this.
Can you convert your checkPointsFolder into a table like this?:
local chekpointsFolder = game.Workspace.Checkpoints:GetChildren
Once you have the folder as a table, you can call a value in the table by something like
print(chekpointsFolder[1])
Just make sure you sort the table using:
table.sort(chekpointsFolder, function(a, b) return a.Name<b.Name end)
Here is the whole test script:
local chekpointsFolder = game.Workspace.Checkpoints:GetChildren()
table.sort(chekpointsFolder, function(a, b) return a.Name<b.Name end)
for i = 1, #chekpointsFolder do
print(chekpointsFolder[i])
end
@ayoub50@FangScripting I did some debugging and found that the issue was with MoveTo(). It is not moving the character to the checkpoint when the player respawns. How do I fix this? I tried reinstalling studio, and it still didn’t work.