How to make random position for raining the whole baseplate

So basically, I want to make the meteor raining the whole baseplate.
This is my code

while true do
	local meteor = game.ServerStorage.Rock:Clone()
	meteor.Name = "Meteor"
	meteor.Position = Vector3.new(math.random(1, game.Workspace.Baseplate.Size.X), 400, math.random(1, game.Workspace.Baseplate.Size.Z))
	meteor.Parent = workspace
	
	meteor.Touched:Connect(function(hit)
		if hit.Name == "Baseplate" then
			wait(1)
			local explosion = Instance.new("Explosion")
			explosion.Position = meteor.Position
			explosion.Parent = workspace
			meteor:Destroy()
		end
	end)
	
	wait()
end

But, It only raining this side.

Is there any solution?

1 Like
local ServerStorage = game:GetService("ServerStorage")

local baseplate = workspace.Baseplate
local basePlateSize, baseplatePos = baseplate.Size, baseplate.Position

local minX, maxX = baseplatePos.X - baseplateSize.X * .5, baseplatePos.X + baseplateSize.X * .5
local minZ, maxZ = baseplatePos.Z - baseplateSize.Z * .5, baseplatePos.Z + baseplateSize.Z * .5

local rng = Random.new(os.clock())

while true do
	local meteor = ServerStorage.Rock:Clone()
	meteor.Name = "Meteor"
	meteor.Position = Vector3.new(rng:NextNumber(minX, maxX), 400, rng:NextNumber(minZ, maxZ))
	meteor.Parent = workspace
	
	meteor.Touched:Connect(function(hit)
		if hit.Name == "Baseplate" then
			wait(1)
			local explosion = Instance.new("Explosion")
			explosion.Position = meteor.Position
			explosion.Parent = workspace
			meteor:Destroy()
		end
	end)
	
	wait()
end
1 Like

It worked, you might want to put .X in your script

Thanks for mentioning that, I’ve fixed it it now :slightly_smiling_face: .