I’m trying to make a script where cubes fall in the area of a big part. in stressing tired on this cuz it isn’t working. I’m also an absolute beginner at this which make it more difficult cuz i don’t know that much
local RS = game:GetService("ReplicatedStorage")
local cubes = RS:WaitForChild("Cubes")
local spawnCube = game.Workspace:WaitForChild("SpawnCubes")
local SizeX = spawnCube.Size.X
local SizeZ = spawnCube.Size.Z
local function spawnCube()
local cube = cubes:GetChildren()[math.random(1, #cubes:GetChildren())]:Clone()
cube.Parent = workspace
cube.Cframe = spawnCube.Cframe + CFrame(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))
end
while wait() do
spawnCube()
end
I’d say use 2 different names for your spawnCube function and your spawnCube variable
something like that would work perfectly fine:
local RS = game:GetService("ReplicatedStorage")
local cubes = RS:WaitForChild("Cubes")
local spawnCube = game.Workspace:WaitForChild("SpawnCubes")
local SizeX = spawnCube.Size.X
local SizeZ = spawnCube.Size.Z
local function generateCube()
local cube = cubes:GetChildren()[math.random(1, #cubes:GetChildren())]:Clone()
cube.Parent = workspace
cube.CFrame = spawnCube.CFrame + CFrame(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))
end
while wait() do
generateCube()
end