Im making a Sort Of dream Game, you walk up to a bed, you press the Proximity Prompt and it will choose a random number, the number goes directly into an If Statement which should teleport you to the Dream, (The Dream will be in the same game), Couldn’t figure it out.
1 Like
can you share your code? what part can’t you figure out?
Sure
DreamId = 0
--Sleeping
script.Parent.ProximityPrompt.Triggered:Connect(function()
DreamId = DreamId + math.random( -1, 1)
end)
-- Dreams
if DreamId == -1 then
end
if DreamId == 1 then
end
if DreamId == 0 then
end
might wanma make a table with all dream place id’s then when the promt is triggerd you select a random one and teleport to it
select a random one by doing
local targetDreamId = tableWitIds[math.random(1, #tableWithIds)]
is there a way i can implement this into Dictionaries?
Something like this would work
local dreams = {}
dreams["Cool"] = "A"
dreams["Sad"] = Vector3.new(0,1000,0)
dreams["Happy"] = {
A=5,
B=6,
}
--etc
local ordered = {}
for name,_ in pairs(dreams) do
table.insert(ordered,name)
end
script.Parent.ProximityPrompt.Triggered:Connect(function()
local dreamName = ordered[math.random(1,#ordered)]
local dreamInfo = dreams[dreamName]
end)
yeah just make a loop in a loop, and keep doing that til ur at the end of the dictionary.
for instance:
---- this dictionary is to group the dreams in themes. to later on set the weights of themes
local dreams = {
nightmares = {
weight = 2 --- the weigth is set to make certain dreams this section appear more then others.,
ids = {
--- place ids of all your nightmares here.
}
},
dreams = {
weight = 5, --- the weigth is set to make certain dreams in this section appear more then others.
ids = {
--- place ids of all your dreams here.
}
}
}
local dreamTable = {}
for _,dream_theme in pairs (dreams) do
--- the amount of the weigth we add a reference of the theme, this way there is a amount of weight chance to get it.
--- insert the whole dictionary item to make sure its a reference and not a copy.
for i = 1, dream_theme['weight'] do
table.insert(dreamTable, dream_theme)
end
end
--- gets u a dream from the theme you give in the parameters
local function getRandomDreamFromTheme (theme) --- theme should be a theme from the dictionary dreams
local selected_dream = theme['ids'][math.random(1, #dream_theme['ids'])]
--- the selected_dream will be your target place ID.
end
--- gets u a dream from any theme
local function getRandomDream ()
local dream_theme = dreamTable[math.random(1, #dreamTable)] --- get a dream theme
local selected_dream = dream_theme['ids'][math.random(1, #dream_theme['ids'])]
--- the selected_dream will be your target place ID.
end
I have not tested it. please let me know if you have any errors