#how do i add Chance to this?
1 messages · Page 1 of 1 (latest)
Script:```lua
local Room = {}
Room.Random = Random.new()
function Room.Generate(PrevRoom)
local PossibleRooms = game.ServerStorage.StraightRooms:GetChildren()
local RandomRoom = PossibleRooms[Room.Random:NextInteger(1, #PossibleRooms)]
local newRoom = RandomRoom:Clone()
newRoom.PrimaryPart = newRoom.Start
newRoom:PivotTo(PrevRoom.End.CFrame)
newRoom.End.Transparency = 1
newRoom.Start.Transparency = 1
newRoom.Parent = workspace.DungeonParts
return newRoom
end
return Room
parts inside folder
well add weight, or a table that defines their chances
can you give example
ok give me a min
ok
can you predefine every room?
forget it i found a better solution
ok..
yes
but put it as a number
not a string ,okay
Room.Random = Random.new()
function Room.Generate(PrevRoom)
local PossibleRooms = {}
for i,v in pairs(PossibleRooms) do
for I = 1,v:GetAttribute("Chance") do
table.insert(PossibleRooms,v)
end
end
local RandomRoom = PossibleRooms[Room.Random:NextInteger(1, #PossibleRooms)]
local newRoom = RandomRoom:Clone()
newRoom.PrimaryPart = newRoom.Start
newRoom:PivotTo(PrevRoom.End.CFrame)
newRoom.End.Transparency = 1
newRoom.Start.Transparency = 1
newRoom.Parent = workspace.DungeonParts
return newRoom
end
return Room
ik
this will add chances using the attribute for every room
put the attribute name instead of "Chance"
so it inserts chance value inside table?
so like 1-100%
yes without the %
yes
try it and tell me
ok
16:44:54.560 ServerScriptService.Script.ModuleScript:14: attempt to index nil with 'Clone' - Server - ModuleScript:14
ok give me a second to look into this
you forgot to get the rooms from the Rooms File i think
for i,v in pairs(game.ServerStorage.StraightRooms:GetChildren()) do
for I = 1,v:GetAttribute("Chance") do
table.insert(PossibleRooms,v)
end
end
yes i did forget indeed
it works
Yay🥳
i see now
oh so you understand, if you want further explanation feel free to ask
ok