My values aren't being accessed

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I would like the current script to be able to print objects stored in a folder which is stored in workspace.

  2. What is the issue? Include screenshots / videos if possible!
    No errors are popping up. And the print statement isn’t printing anything.

  3. What solutions have you tried so far?
    When I moved the script in workspace and make minor changes to code- for example the folder pathway- the print statement work. I would like the script to run in starterPlayerscripts.
    I tried adding a player added event and that didn’t work. Is it possible to run this kind of script in starterPlayerscripts?

local game_workspace = game:GetService("Workspace")
local folder  = game_workspace.Spawners

--local spawner_touched  = {}


--[[
local function append_checkpoint(checkpoint)
	local checker = false --means that the checkpoint isn't in the table
	
		table.insert(spawner_touched,checkpoint)

	return checker
end

--]]

--[[
local function is_humanoid()
	local val = false
	local player = script.Parent.Parent
	local char = player.Character or player.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	if humanoid then 
		val = true
	end
	return val	
end
--]]

--[[
local function touched_checkpoint(checkpoint)
	
	if is_humanoid() and append_checkpoint() == false then
		print("Part is touched:")
		script.Parent.leaderstats.Obbylvl.Value = script.Parent.leaderstats.Obbylvl.Value + 1
	end
end
--]]


for index, val in ipairs(folder:GetChildren()) do
	print(val.Name)
end


Is there another script creating these values and putting them into the folder?

You could also try putting a task.wait(1) before the for loop, just to test if it may be a replication issue or if the values are being added after the script runs.

Also, just wondering, why are you defining game_workspace? There is a global variable called workspace.

1 Like

For loop will not run and move onto the next line if the given table length is 0, so check the folder’s childrens length.

I agree, by the time the script reaches the for loop its too late, there are no childrens inside the folder