I’m trying to make a script that places a part on a floor at a random position on it, im setting the position to the middle and then adding the value of the floors position, I’m having trouble setting the random position
Error :
Script :
local X = script.Parent.Size.X
local Y = script.Parent.Size.Y
local Z = script.Parent.Size.Z + 0.1
local Center = Floor:GetBoundingBox()
local function messSpawn()
local XPos = Vector3.new(math.random(0, X))
local YPos = Vector3.new(math.random(0, Y))
--spawn thing
local Mess = game.ReplicatedStorage.Mess:Clone()
Mess.Parent = script.Parent.Messes
Mess.Anchored = true
Mess.CFrame = Center
Mess.CFrame.X = CFrame.new(XPos)
Mess.CFrame.X = CFrame.new(YPos)
print("Y = "..Y, "X = "..X)
end
local Event = game.ReplicatedStorage.RemoteEvent
Event.OnServerEvent:Connect(messSpawn)
I was able to figure it out, heres the working script if anyone needs it
local X = tostring(script.Parent.Size.X / 2)
local Y = tostring(script.Parent.Size.Y + 0.1) --up n down
local Z = tostring(script.Parent.Size.Z / 2)
local Center = Floor:GetBoundingBox()
local CenterStr = tostring(Center)
local MessFolder = script.Parent
MaxInstanceSetting = 10 --roughly the instances allowed at any one time
MaxInstances = false
--setting the center of the area
local MiddlePart = Instance.new("Part")
MiddlePart.Anchored = true
MiddlePart.Parent = script.Parent
MiddlePart.Name = "probably the middle of the floor"
MiddlePart.CFrame = Center
MiddlePart.Size = Vector3.new(1, 2, 1)
local function messSpawn()
local XPos = tonumber(math.random(-X, X))
local ZPos = tonumber(math.random(-Z, Z))
local V3Pos = Vector3.new(XPos, Y, ZPos)
local FinalPos = Vector3.new(XPos, Y, ZPos)
--spawn thing
local Mess = game.ReplicatedStorage.Mess:Clone()
Mess.CFrame = MiddlePart.CFrame + FinalPos
Mess.Parent = script.Parent.Messes
Mess.Anchored = true
end```