Blocks spawn and fall in part area

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

Example

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
1 Like

welll, to I see that you didnt write "CFrame" properly. Other than that I dont see much of an error

cube.Cframe = spawnCube.Cframe + CFrame(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))
to
cube.CFrame = spawnCube.CFrame + CFrame(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))

it also says

ServerScriptService.Script:12: attempt to index function with ‘CFrame’

it also doesnt fall it just spawns on the baseplate

oh I see lol

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

ServerScriptService.Script:12: attempt to call a table value

it just spawns on the baseplate

Pretty sure the reason why its just spawning on the baseplate is because there’s an error..

Could I have a look at the ReplicatedStorage and Workspace?

alr

I just ran some code and its kinda silly :sob:

  • The error was you forgot to add .new after CFrame
  • You cant add up 2 CFrames together, you need to multiply them; you can add Vector3s to the CFrames to tweak the Position
    :

cube.CFrame = spawnCube.CFrame * CFrame.new(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))

or

cube.CFrame = spawnCube.CFrame + Vector3.new(math.random(-SizeX,SizeX), 90, math.random(-SizeZ,SizeZ))

2 Likes

Did everything turn out to work properly?

1 Like

it worked tysm!! i guess it was as simple as that. i was also busy mb :sweat_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.