Void Spawning Randomly

Good afternoon, this is my first post, so I hope it’s structured correctly. I need some script help please.

Problem

I’m currently creating an Obby and have a checkpoint system in place. (I don’t have spawn points because it works based off numbered parts that have their own folder.) The problem I have is people spawn into the void randomly. However, I need help to identify and fix it. (The output doesn’t show script errors either, so it’s hard to identify why it’s happening.)

About my checkpoint system

The scripts I have in place for the checkpoint system don’t live within the parts themselves, they’re one script file that lives in the ServerScriptService side of the game and it connects to the folder.

Things I’ve tried

  1. I have tried making all the checkpoints “SpawnPoints” but they ignored my script and people kept spawning at a random spawn point.

  2. I tried having one spawn point and the rest of the platforms numbered parts, again people kept spawning at the spawn point.

Here is the script I have setup for my checkpoints. (This script lives in the ServerScriptService) and (Progress is stored using a different script. I will upload my save script file too in case, that’s the culprit)

local Nodes = game.Workspace.Nodes


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local node = Instance.new("IntValue")
	node.Name = "Node"
	node.Value = 0
	node.Parent = leaderstats
	
	
	local prestige = Instance.new("IntValue")
	prestige.Name = "Prestige"
	prestige.Value = 0
	prestige.Parent = leaderstats

	
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(Nodes[node.Value].Position)
		hum.Touched:Connect(function(hit)
			if hit.Parent == Nodes then
				if tonumber(hit.Name) == node.Value + 1 then
					node.Value = node.Value + 1
				end
			end
		end)
	end)
end)

game.ReplicatedStorage.Prestige.OnServerInvoke = function (player)
	if player.leaderstats.Node.Value == 41 then
		player.leaderstats.Prestige.Value += 1
		player.leaderstats.Node.Value = 0

		player:LoadCharacter()
	end
end 

Here’s my saving script

local DataStoreService = game:GetService("DataStoreService")
local Nodes = DataStoreService:GetDataStore("Nodes")
local Prestige = DataStoreService:GetDataStore("Prestige")


game.Players.PlayerAdded:Connect(function(player)
	local data
	local success, errorMessage = pcall(function()
		data = Nodes:GetAsync(player.UserId)
	end)

	if success then
		player.leaderstats.Node.Value = data
	else
		warn(errorMessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data
	local success, errorMessage = pcall(function()
		data = Nodes:SetAsync(player.UserId, player.leaderstats.Node.Value)
	end)

	if success then
		print("Data Saved")
	else
		warn(errorMessage)
	end
end)


game.Players.PlayerAdded:Connect(function(player)
	local data
	local success, errorMessage = pcall(function()
		data = Prestige:GetAsync(player.UserId)
	end)

	if success then
		player.leaderstats.Prestige.Value = data
	else
		warn(errorMessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local data
	local success, errorMessage = pcall(function()
		data = Prestige:SetAsync(player.UserId, player.leaderstats.Prestige.Value)
	end)

	if success then
		print("Data Saved")
	else
		warn(errorMessage)
	end
end)


game:BindToClose(function()
	for i, v in pairs(game.Players:GetChildren()) do
		v:Kick("Server Closed")
	end

	wait(2)
end)

Image 1 - ServerScriptService
I1

Image 2 - ServerScriptService
I2

Image 3 - Workplace.Nodes
I3

1 Like

When the game is running, check to see if the node.Value value is increasing. As well, in the CharacterAdded function, move the character first, rather than waiting a frame.

If the node value is increasing, and the issue still persists, I would check to assure that node is an IntValue. You could also try placing a print statement into the characrerAdded function to check and see if the function is even firing at all.

1 Like

Try to initialize node.Value to a different number like 2 or 3 and see if the player is moved to that place when the game starts. The issue may be that even though the value of node is being changed, the script isnt detecting that. Alternatively, the moving of the character may not be working.

1st Check. I changed the value of 5 here and it didn’t change in game. I’m still on Node 2.

local node = Instance.new("IntValue")
	node.Name = "Node"
	node.Value = 5
	node.Parent = leaderstats

2nd Check - I printed the function for player added and it doesn’t show anything in the output.

player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(Nodes[node.Value].Position)
		hum.Touched:Connect(function(hit)
			if hit.Parent == Nodes then
				if tonumber(hit.Name) == node.Value + 1 then
					node.Value = node.Value + 1
					print (char, "Function working")
				end
			end
		end)
	end)
end)

Isnt Nodes the datastore? The touched event is if hum touches the datastore or am i reading it incorrectly? If you meant the folder it should have brackets on it i believe… also helps to name the folder differently than your variable Nodes.

The folder is called Nodes and the datastore is called Nodes.

Hmmm, maybe it’s getting confused with it being called the same?

Maybe try this:

if hit:FindFirstAncestor("Nodes") then

None of these actually helped me, I would however, like to thank you all for looking at it for me. I’ll keep investigating why. :slight_smile: