Hello my script is not working and its suppose to clone a map in the game and its using a module script and a regular script to connect with each other here are both parts of the script that are not working.
–Module script
function module.SelectChapter()
local rand = Random.new()
local chapters = game.ReplicatedStorage.Chapters:GetChildren() --Table of all maps in the game available
local chosenChapter = chapters[rand:NextInteger(1,#chapters)]
return chosenChapter
end
–Regular Script
local chosenChapter = Round.SelectChapter()
You shouldn’t really use a module script I would just do.
–RegularScript
local availableMaps = game.ReplicatedStorage.Chapters:GetChildren() -- I recommend putting them in server storage, not replicated storage.
local selectedMap = math.random(1, #availableMaps)
local clonedMap = availableMaps[selectedMap]:Clone()
clonedMap.Parent = workspace -- use this instead of game.Workspace
function module.SelectChapter()
local chapters = game.ReplicatedStorage.Chapters:GetChildren() --Table of all maps in the game available
local chosenChapter = chapters[math.random(1,#chapters)]
return chosenChapter
end
other code
local Round= require()
local chosenChapter = Round.SelectChapter()
local clonedChapter = chosenChapter:Clone()
clonedChapter.Name = “Map”
clonedChapter.Parent = workspace
I recognise this code. It’s very important that you follow the steps in the tutorial, otherwise issues like this can occur. As for when you post threads to this category, please debug first then post a thread if you can’t figure it out after consulting the tutorial again - with the exact error.
@iiFusionzX Yes you should use a ModuleScript where possible. They aren’t useless and are able to be used on both environments. They are good as reusable pieces you can transfer anywhere, be it a library or a container of data/constants. As for OP’s specific case, it’s from one of Alvin_Blox’s tutorials, how to create a Piggy game.
@FerbZides math.random and Random.new run on the same algorithm. NextInteger is not the problem. If you don’t care for all the benefits the Random object provides then you can still use math.random, otherwise this suggestion doesn’t change what the code is doing fundamentally.