Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Spawn A Model Randomly Without Lining Them Up?

I learnt to code random positions from a Youtube video. Then, I applied it to make my model fall from random positions. Disappointingly, the grapes only lined up. DM on discord Starlight#7272 if you want more details. This is my code:

local Grape = game.ReplicatedStorage:WaitForChild('Grape')
local grapeHeight = 100
local MinX = -100
local MaxX = 100
local MaxZ= 100
local MinZ = -100


math.randomseed(tick())
local function grape()
	local GrapeCopy = Grape:Clone()
	local x = math.random(MinX,MaxX)
	local z math.random(MinZ,MaxZ)
GrapeCopy.Parent = workspace
GrapeCopy.CFrame = CFrame.new(x,grapeHeight,z)
game:GetService('Debris'):AddItem(GrapeCopy,math.random(10,15))


while true do
	grape()
	wait(1)
end

Could anyone explain why it is not working?

1 answer

✓ Accepted answer

Not sure why that one didn't work, but I re-wrote that script into a shorter version and it works perfectly fine.

Here is what I did.

local minX = -100
local maxX = 100
local norY = 100
local minZ = -100
local maxZ = 100

while wait(1) do
	math.randomseed(tick())
	local grape = game:GetService("ReplicatedStorage"):WaitForChild("Grape"):Clone()
	grape.Parent = game:GetService("Workspace")
	grape.CFrame = CFrame.new(math.random(minX,maxX),norY,math.random(minZ,maxZ))
	game:GetService("Debris"):AddItem(grape,math.random(10,15))
end

I recommend putting math.randomseed(tick()) inside of the function so it randomizes every time.

I just compiled it down into less code is about it, and it works. It ranges from -100 to 100, and does not go into a straight line.

Hope this helped!

4 comments

0

I’m gonna check this when I’m home. Thank you. Also, it may be because I didn’t put random.seed(tick()) in the function, which is why I didn’t work.

0

I'm not sure, but I'm glad to be of help!

0

Oh I forgot the equal mark on line 13. Thanks for shortening the script.

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.