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

Books being cloned on the same position?

I have tried both the "Run" and "Play" testing styles, and none of them work. Although I have not tried a Studio test server.

My script is a regular one and is parented to a folder.

The output does not show any errors, and adding a print() statement on line 14 works perfectly.

When I run the script, every book spawns on the same position, which is not what I expected. I want the books to be separated.

-- Repeat X for 18 times --
for i = 1, 18 do
	-- A directory into the "Books" folder in the "ServerStorage" service.
	local booksFolder = game.ServerStorage.Models.Books
	-- Get an array of every book color and pick a book randomly. --
	local bookList = booksFolder:GetChildren()
	local randomBook = bookList[math.random(1, #bookList)]
	-- Clone the chosen book. --
	local bookClone = randomBook:Clone()
	-- Dictates the orientation of the book. --
	local orientationIdentifier = math.random(1, 5)
	-- Dictates the position of the book.
	local bookPosition = Vector3.new(script.Parent.BookPositionGuide.Position.X, script.Parent.BookPositionGuide.Position.Y, script.Parent.BookPositionGuide.Position.Z + 0.5)
	-- Place the book according to the "bookPosition" variable.
	bookClone.Position = bookPosition
	-- Parent the book into the script's parent. --
	bookClone.Parent = script.Parent
	-- If the orientationIdentifier's integer is equal to 5, then... --
	if orientationIdentifier == 5 then
		-- Rotate the book 180°. --
		bookClone.Orientation = Vector3.new(0, 180, 0)
	end
end

1 answer

Never mind, I have fixed the script by changing the bookPositionGuide's position.

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