Hello, I have been working on a script that will spawn pets randomly on a part and here is what I did:
local plot = workspace.PetSpawns
for i = 1, 10 do
local pet = game.ReplicatedStorage.Pet:Clone()
pet.Parent = workspace.Pets
pet.Name = 'Pet'
local x = math.random(plot.Position.X - plot.Size.X/2 , plot.Position.X + plot.Size.X/2)
local z = math.random(plot.Position.Z - plot.Size.Z/2 , plot.Position.Z + plot.Size.Z/2)
pet:SetPrimaryPartCFrame(CFrame.new(x,pet.PrimaryPart.Size.Y/2 + plot.Size.Y/2,z))
end
It works fine except I want to position the pet exactly on the top of the plot but this happens:
How do I fix this?
Thank you!
local plot = workspace.PetSpawns
for i = 1, 10 do
local pet = game.ReplicatedStorage.Pet:Clone()
pet.Parent = workspace.Pets
pet.Name = 'Pet'
local x = math.random(plot.Position.X - plot.Size.X/2 , plot.Position.X + plot.Size.X/2)
local z = math.random(plot.Position.Z - plot.Size.Z/2 , plot.Position.Z + plot.Size.Z/2)
pet:SetPrimaryPartCFrame(CFrame.new(x,plot.Position.Y + pet.PrimaryPart.Size.Y/2,z))
end
```
local x = math.random(
plot.Position.X - plot.Size.X/2 + pet.PrimaryPart.Size.X/2,
plot.Position.X + plot.Size.X/2 - pet.PrimaryPart.Size.X/2
)
-- repeat for z