Using "CollectionService" to refer ServerScriptService Script to CheckPoints

Added multiple CheckPoints to Workspace and trying to refer CheckPoint Script amongst CollectionService so that one Script can apply to mentioned parts.

ServerScriptService > Script:


for _, CheckPoint in CollectionService:GetTagged("CheckPoint")do	
	local spawn = script.Parent
	workspace.CheckPoint.Touched:Connect(function(hit)
		if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") 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
		end
	end)
end
1 Like
for _, CheckPoint in CollectionService:GetTagged("CheckPoint")do	
	local spawn = script.Parent
	workspace.CheckPoint.Touched:Connect(function(hit)

you arent referencing the checkpoint, you’re just referencing a static one in the workspace.

You can instead try

game.Workspace:FindFirstChild(CheckPoint).Touched:Connect(function(hit))
1 Like

I did and not to be rude and all, but it’s wrong my guy.

2 Likes

mb i meant to do FindFirstChild lmao

1 Like

try printing out Checkpoint and see if it returns a non nil value

1 Like

this is the error it gives me when it tries to teleport the player to the CheckPoint after death.
CFrame is not a valid member of ServerScriptService "ServerScriptService" - Server - Script:21

1 Like