Scripting a chunk loader

  1. What do you want to achieve?
    I want to make it so that whenever a player steps on a a part, it replaces with another random part from the replicated storage and removes the part that is stepped upon

  2. What is the issue?
    I get this error, ā€œ12:18:30.064 Workspace.UnloadedChunk(20x1x20).ChunkLoader:7: attempt to get length of a Instance value - Server - ChunkLoader:7ā€

  3. What solutions have you tried so far?
    Tried asking my friends.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChunkFolder = game.ReplicatedStorage.Chunks
local Chunks = ChunkFolder:GetChildren()
local UnloadedChunk = script.Parent

local function ChunkLoader()
	local SelectedChunk = ChunkFolder[math.random(#ChunkFolder)]
	
	SelectedChunk:Clone().Vector3 = UnloadedChunk.Vector3
	SelectedChunk.Parent = game.Workspace
	SelectedChunk.Name = "LoadedChunk"
	
	UnloadedChunk:Destroy()
end

UnloadedChunk.Touched:Connect(ChunkLoader())
1 Like

You are trying to set an instance to an instance.

You are trying to get the length of ChunkFolder. I assume you want the # of children, so the correct code would be:

local SelectedChunk = ChunkFolder[math.random(#Chunks)]

I’d be really interested to learn how this will work in the future.

1 Like