Randomized cframe

function SpawnMobs(Room, Enemy)
	local Mob = game:GetService("ServerStorage").Enemies:FindFirstChild(Enemy):Clone()
	Mob.Parent = game:GetService("Workspace").Enemies
	local Spacing = 5
	local Spawner = Room:FindFirstChild("MobSpawn")
	Mob.PrimaryPart.CFrame = {Spawner.Position + math.random(-Spawner.Size.X / Spacing, Spawner.Size.X / Spacing), 2.5, math.random(-Spawner.Size.Z / Spacing, Spawner.Size.Z / Spacing)}
end

the error

ServerScriptService.GenerateRooms:33: attempt to perform arithmetic (add) on Vector3 and number
i dont understand the problem

Because your actually trying to add number on Vector3. You need to make not just math.random.
Try this:

function SpawnMobs(Room, Enemy)
	local Mob = game:GetService("ServerStorage").Enemies:FindFirstChild(Enemy):Clone()
	Mob.Parent = game:GetService("Workspace").Enemies
	local Spacing = 5
	local Spawner = Room:FindFirstChild("MobSpawn")
	Mob.PrimaryPart.CFrame = {Spawner.Position + Vector3.new(math.random(-Spawner.Size.X / Spacing, Spawner.Size.X / Spacing), 2.5, math.random(-Spawner.Size.Z / Spacing, Spawner.Size.Z / Spacing))}
end
2 Likes

i got an error and it says that it got a table instead

I think you meant to use CFrame.new.

1 Like