Spawning a Model in Multiple Locations

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 to have it where the models can spawn at multiple places, eg: if the first place is taken, it spawns at the second, etc.


    ^ The one on the right is the one the models spawn at currently, however I want to make it where I can add more places where models can spawn. The one on the left does not work, and thats what I want to work.

  2. What is the issue?
    I cannot seem to wrap my head around how to do this at the moment in time.

  3. What solutions have you tried so far?
    So I looked around on the forum, and couldn’t find anything of any use to myself.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Spawning Model:

local SS = game:GetService("ServerStorage")
local Cloneables = SS.Cloneables
local tc_Train = Cloneables.Train

local RS = game:GetService("ReplicatedStorage")
local REs = RS.REs
local rE_Spawn = REs.SpawnTrain

local spawnPart = game.Workspace.SpawnPart

local function CloneTrain(plr)
    local train = tc_Train:Clone()
    train.Name = plr.Name.."'s Train"
    train.Owner.Value = plr
    train:SetPrimaryPartCFrame(spawnPart.CFrame)
    train.Parent = game.Workspace
end

rE_Spawn.OnServerEvent:Connect(function(plr, msg)
    print("Will clone a train for: "..plr.Name..", and the message is: "..msg..".")
    CloneTrain(plr)
end)

Text Button:

local RS = game:GetService("ReplicatedStorage")
local REs = RS.REs
local rE_Spawn = REs.SpawnTrain

script.Parent.MouseButton1Click:Connect(function()
    rE_Spawn:FireServer("Train")
end)

Other Images:
image

image

image

1 Like

Have a table of possible positions at the beginning of the script, then use table.remove to get the next available position.

Here is an example:

local positions = {Vector3.zero, Vector3.one}

...

local function CloneTrain()
	...
	local location = table.remove(positions, 1) -- Gets the first element of the locations table
	...
end

...

Hi there, sorry for the late reply. Is this how I’d implement it?

local positions = {Vector3.zero, Vector3.one}

local SS = game:GetService("ServerStorage")
local Cloneables = SS.Cloneables
local tc_Train = Cloneables.Train

local RS = game:GetService("ReplicatedStorage")
local REs = RS.REs
local rE_Spawn = REs.SpawnTrain

local spawnPart = game.Workspace.SpawnPart

local function CloneTrain(plr)
	local train = tc_Train:Clone()
	train.Name = plr.Name.."'s Train"
	train.Owner.Value = plr
	train:SetPrimaryPartCFrame(spawnPart.CFrame)
	train.Parent = game.Workspace
	local location = table.remove(positions, 1) -- Gets the first element of the locations table
	
	rE_Spawn.OnServerEvent:Connect(function(plr, msg)
		print("Will clone a train for: "..plr.Name..", and the message is: "..msg..".")
		CloneTrain(plr)
	end)
end

When running this, I get this: (This is the weld script to hold the train together)

table.Insert is not a valid function. The correct syntax is table.insert. Most of the global libraries such as table and os are all in lowercase.

So using that, I do not get an error now: Bug Report - YouTube

You only displayed the client logs just then, you should also check the F9 server logs as well.

Additionally, you can check studio console to find your bugs there.


Top one is on the server, bottom is on the client. Forgot to mention that, apologies.