Greetings,
I want to create an area for say, 5 random chests to spawn in. I would like to know the best way to accomplish this using the parameters I have, because I am new to Roblox development and this is why I seek assistance. I would like to have the chests randomly spawn in areas around the map (region shown here).
I can’t wrap my head around how to do this. Any help will be greatly appreciated.
I would suggest looking into Region3 to do this.
1 Like
I will look into it. Thanks for the feedback.
local SingletonRandom = Random.new(tick())
local function GetRandom(Min,Max)
local e = SingletonRandom:NextNumber(Min,Max)
return e
end
local function SelectRandomPos(Object, Pos1, Pos2)
Object:SetPrimaryPartCFrame(CFrame.new(GetRandom(Pos1.X, Pos2.X),GetRandom(Pos1.Y, Pos2.Y),GetRandom(Pos1.Z, Pos2.Z)))
end
Try to use this code, Object is the model that you’re going to move, Pos1 and Pos2 are blocks to reference the position to place the Object randomly, I hope this helps you.
2 Likes
Thank you. I will try to incorporate this in my game and will improve upon it.
Quick question to Area3:
How do you find a random coordinate inside of an area?
Is it something like math.random(), or something else?