Recently, i started working on a RNG game where you get cubes (based off another one because they challenged me to make it while using less code) and i want to the cubes to spawn in the baseplate no matter the size
What do you want to achieve? Keep it simple and clear!
I already made a system for the spawning, but i dont want it to use math.random or random.new, i want it to always spawn inside the baseplate even if i resize it
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
Sadly, i cant find any solutions, i tried to math.random using the size but it didnt seem to work
How would i be able to make it?
Fun fact: apparently they used 600 lines for the RNG… i made a really simple system under 50… actually way less
Why exactly you don’t want to use math.random? Cause that seems like the most obv variant for me where you pick 1 number for x and one for z where max and min are based on sizes of baseplate
local b=workspace.Baseplate s=b.Size p=b.Position d=tick()%1
function r()d=(d*9301+49297)%233280 return d/233280 end
c=Instance.new('Part',workspace) c.Size=Vector3.one*2 c.Anchored=true
c.Position=Vector3.new(p.X-s.X/2+s.X*r(),p.Y+s.Y/2+1,p.Z-s.Z/2+s.Z*r())
local basePart = workspace.BasePart -- Platform
local templatePart = workspace.Cube -- The part I used
local function spawn()
-- Size
local baseSize = basePart.Size
local spawnSize = templatePart.Size
-- Spawn range
local xRange = (baseSize.X - spawnSize.X) / 2
local zRange = (baseSize.Z - spawnSize.Z) / 2
-- Randomise
local offsetX = math.random() * 2 * xRange - xRange
local offsetZ = math.random() * 2 * zRange - zRange
-- New CFrame
local baseCFrame = basePart.CFrame
local spawnHeight = (baseSize.Y + spawnSize.Y) / 2
local newCFrame = baseCFrame * CFrame.new(offsetX, spawnHeight, offsetZ)
-- Clones the part
local newPart = templatePart:Clone()
newPart.CFrame = newCFrame
newPart.Parent = workspace
end
wait(5)
while true do
wait(1)
spawn()
end
Just so you guys know, the parts are stored in the script to spawn them, i might use math.random though… as i dont think theres another way (Thanks though, ill try out the code, with edits… of course)
All you said was you can’t use math.random or random.new… You didn’t say I couldn’t make up my own random… That’s 4 lines and enough mathmagic to keep anyone guessing for a bit…