Whenever I run the script it always gives the error 'ServerScriptService.GenerationSettings:22: attempt to index local 'currentPath' (a nil value)'. I'm not sure why its happening.
The Module Script:
local generateModule = {}
local replicatedStorage = game:GetService('ReplicatedStorage')
local serverStorage = game:GetService('ServerStorage')
local pathLength = 80
local plainPaths = serverStorage:WaitForChild('PlainPaths'):GetChildren()
local obstructionPaths = serverStorage:WaitForChild('ObstructionPaths'):GetChildren()
generateModule.GenerateNewPath = function (currentPathNumber, currentPath)
local decidedPathType = math.random(1, 2)
if decidedPathType == 1 then
decidedPath = plainPaths[math.random(1, #plainPaths)]
else
decidedPath = obstructionPaths[math.random(1, #obstructionPaths)]
end
decidedPath:Clone().Parent = workspace
decidedPath.PathNumber.Value = currentPathNumber + 1
decidedPath.Position = currentPath.Position + Vector3.new(0, 0, pathLength)
local decidedPathType2 = math.random(1, 2)
if decidedPathType2 == 1 then
decidedPath2 = plainPaths[math.random(1, #plainPaths)]
else
decidedPath2 = obstructionPaths[math.random(1, #obstructionPaths)]
end
decidedPath2:Clone().Parent = workspace
decidedPath2.PathNumber.Value = decidedPath + 1
decidedPath2.Position = decidedPath.Position + Vector3.new(0, 0, pathLength)
local lastPath = currentPathNumber - 1
for _, path in pairs (workspace) do
if path.Name == 'Path1' or path.Name == 'Path2' or path.Name == 'Path3' or path.Name == 'Path4' then
if path.PathNumber.Value == lastPath then
path:Destroy()
end
end
end
end
return generateModule
The Touch Script:
local serverStorage = game:GetService('ServerStorage')
local serverScriptService = game:GetService('ServerScriptService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local generationModule = require(serverScriptService.GenerationSettings)
local path = script.Parent.Parent
local pathNumber = path:WaitForChild('PathNumber')
function onTouch(hit)
local humanoid = hit.Parent:FindFirstChild('Humanoid')
if pathNumber.Value > 3 and humanoid then
generationModule.GenerateNewPath(pathNumber.Value, path)
script.Disabled = true
end
end
script.Parent.Touched:connect(onTouch)

3 comments
Also this for some reason generates it whenever theres a collision even though i disabled the script, so it ends up generating hundreds of models.
current path isn't a variable.
Its not a variable its an argument in a form of a model.