#simple generation script
1 messages · Page 1 of 1 (latest)
-- Variables
local checkpoint = script.Parent -- The checkpoint brick
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Put your models/parts in a folder inside ReplicatedStorage
local itemsFolder = ReplicatedStorage:WaitForChild("Items") -- change "Items" to your folder name
-- Settings
local spawnDistance = 75 -- studs ahead
-- Function to spawn a random item
local function spawnRandomItem()
-- Pick a random child from the folder
local children = itemsFolder:GetChildren()
if #children == 0 then return end -- no items
local randomItem = children[math.random(1, #children)]
-- Clone and position it
local clone = randomItem:Clone()
local spawnPosition = checkpoint.Position + (checkpoint.CFrame.LookVector * spawnDistance)
clone:SetPrimaryPartCFrame(CFrame.new(spawnPosition))
clone.Parent = workspace
end
-- Event when player touches checkpoint
checkpoint.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
spawnRandomItem()
end
end)
Script using ChatGPT should work
Place the script in ServerScriptService and change the directories to those which you mentioned in your Q
small issue, i want this to generate infinitely so it would have to be in each module
** You are now Level 2! **
Infinite as in time or infinite as in per model?
like if i touch the checkpoint of a module, it will generate another and then when i touch the next, another
so on and so forth
Ah ok
use collection service
So per model
basically a bridge that builds itself as i progress
Change the local checkpoint = script.Parent -- The checkpoint brick into local checkpoint = {}
** You are now Level 1! **
Then go for _, child in [folder with all the modules you are talking about] do table.insert(checkpoint, child) end
Did it work?
2 secpmds
local checkpoint = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local itemsFolder = ReplicatedStorage:WaitForChild("Items")
local checkpointFolder = workspace:WaitForChild("Checkpoints")
for _, child in pairs(checkpointFolder:GetChildren()) do
table.insert(checkpoint, child)
end
local spawnDistance = 75
local function spawnRandomItem(checkpointPart)
local children = itemsFolder:GetChildren()
if #children == 0 then return end
local randomItem = children[math.random(1, #children)]
local clone = randomItem:Clone()
local spawnPosition = checkpointPart.Position + (checkpointPart.CFrame.LookVector * spawnDistance)
clone:SetPrimaryPartCFrame(CFrame.new(spawnPosition))
clone.Parent = workspace
end
for _, checkpointPart in pairs(checkpoint) do
checkpointPart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
spawnRandomItem(checkpointPart)
end
end)
end
like this?
good but have _ after the fore
local part = script.Parent
local module = part.Parent
local checkpointsFolder = workspace:WaitForChild("Checkpoints")
local Players = game:GetService("Players")
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local modules = checkpointsFolder:GetChildren()
if #modules > 0 then
local chosenModule = modules[math.random(1, #modules)]:Clone()
local offset = module.PrimaryPart and module.PrimaryPart.CFrame.LookVector or Vector3.new(0, 0, 1)
local newPos = module:GetPrimaryPartCFrame() * CFrame.new(0, 0, -75)
chosenModule.Parent = workspace
chosenModule:SetPrimaryPartCFrame(newPos)
end
end
end)
found a very simple fix, thanks always