Spawn part without a script!

In the ServerStorage there is a part “Sand” with a script.
I decided to make a spawn, but not everything is so simple, part was spawned and it was impossible to interact with it. The script in part is correct, I checked.

script for spawn:

local serverstorage = game:GetService(“ServerStorage”)

local arrowSpawns2 = game.Workspace.ItemSpawnAreas.SandSpawns:GetChildren()[math.random(1, #game.Workspace.ItemSpawnAreas.SandSpawns:GetChildren())]

function play(delay,located)

wait(delay)

serverstorage:WaitForChild(“Sand”):Clone()

serverstorage:WaitForChild(“Sand”).CFrame = located.CFrame

serverstorage:WaitForChild(“Sand”):Clone().Parent = game.Workspace

end

while true do

play(5,arrowSpawns2)

end

I don’t know what exactly your goal is but there are numerous problems with your script. I’ve made a fixed version:

local serverStorage = game:GetService("ServerStorage")

local spawns = workspace.ItemSpawnAreas.SandSpawns:GetChildren()
local _delay = 5

while true do
	local randomSpawn = spawns[math.random(1, #spawns)]
	wait(_delay)

	local newSand = serverStorage.Sand:Clone()
	newSand.CFrame = randomSpawn.CFrame
	newSand.Parent = workspace
	
	wait(_delay)
end

The only performance difference is that it picks a new spawn each loop.

1 Like