Hi everyone, i’m trying to make a game with some minigames inside, in one of them you need to go through some Doors Lines and go through the one who is opened
(Do you remember Takeshi’s Castle or Fall Guys level? Is similiar to that)
What shoud happen with this level so?
There are like 8 lines of 7 Doors each in this level, the script should:
Take randomically 3 of the 7 doors and lock them (Just anchor and change their color with red, for tests)
In the other 4 green doors 1 or 2 will have a trap inside them (Exactly as Takeshi’s Castle)
And will change their color to Cyan/Blue
Picture3
And this will repeat for the remaining 7 lines
Why are you doing this so complex?
To make the minigame change everytime so people can’t memorize the correct path and win so easily, that will ruin the competition between players.
The issue:
Actually i’m trying making my own script for this and i know that what i’ve done is really complex and does not even work fine so
I Am Once Again Asking for Your Scripting Support
My actual Script
LineNumber = math.random(1,1)
LockNumber = 0
OpenNumber = 0
TrapNumber = 0
doing = 0
if LineNumber == 1 then
repeat
doing = doing +1
OldNumber = LockNumber
LockNumber = math.random(1,7)
if OldNumber == LockNumber then
print("Oh shit")
doing = doing -1
end
print("Randomized Number: " ..LockNumber)
print("Old Number: " ..OldNumber)
print("Doing number: " ..doing)
print("----------------------") --Just to make space between Numbers..
wait(3)
if doing == 1 then
LockedDoor1 = LockNumber
elseif doing == 2 then
LockedDoor2 = LockNumber
elseif doing == 3 then
LockedDoor3 = LockNumber
end
until doing == 3
print(LockedDoor1)
print(LockedDoor2)
print(LockedDoor3)
if LockedDoor1 or LockedDoor2 or LockedDoor3 == 1 then
print("Why is always printed?")
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 2 then
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 3 then
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 4 then
print("Test")
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 5 then
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 6 then
elseif LockedDoor1 or LockedDoor2 or LockedDoor3 == 7 then
end
end
NOTE: The Doors are composed by 4 parts to make them look like are being crashed so every door is actually a model with 4 parts inside.
I’ll sure study a lot about tables until i’ll master them, about changing all the parts inside a model i can use :GetChildren(Code) or there is another way?
The biggest problem with your existing code is that a conditional like this:
probably isn’t checking what you want. Were you meaning to test something like this: if LockedDoor1==1 or LockedDoor2==1 or LockedDoor3==1 then
or were you actually trying to test that LockedDoor1 and LockedDoor2 are uninitialized (so nil) or set to false? You don’t show where these are declared, so impossible for us to tell.
Overall, you can probably implement this who system without a single if .. then conditional, just by making an array of 7 values, e.g. { “locked”,“locked”, “locked”,“open”,“open”,“trapped”,“trapped” } and shuffling it with any simple shuffling algorithm. You can shuffle like: table.sort(a, function(a,b) return math.random()<0.5 end)
or do something more like implement a Fisher-Yates type swap (still only like 4 lines of code).
Heya! So, i made a simple system for the Doors and this is actually working! The only problem now is: how do i edit the parts inside the model? I mean, models like “Door1, Door2, etc” are actually “TrappedDoors[1]” or “LockedDoors[3]” And i’m searching for how to edit them
Actual code:
L1L = workspace.Working.DoorsLine1 --L1L is for Line1Location
OpenDoors = {L1L.Door1, L1L.Door2, L1L.Door3, L1L.Door4, L1L.Door5, L1L.Door6, L1L.Door7}
LockedDoors = {}
TrappedDoors = {}
m = 0
b = 7
m2 = 0
b2 = 4
print("The extracted numbers are:")
repeat
m = m +1
b = b -1
n = math.random(1,b)
table.move(OpenDoors,n,n,m,LockedDoors)
table.remove(OpenDoors,n)
wait(1)
until m == 3
repeat
m2 = m2 +1
b2 = b2 -1
n2 = math.random(1,b2)
table.move(OpenDoors,n2,n2,m2,TrappedDoors)
table.remove(OpenDoors,n2)
wait(1)
until m2 == 2
print("----------")
print("Locked Doors:")
print(LockedDoors[1])
print(LockedDoors[2])
print(LockedDoors[3])
print("----------")
print("Opened Doors:")
print(OpenDoors[1])
print(OpenDoors[2])
print("----------")
print("Trapped Doors:")
print(TrappedDoors[1])
print(TrappedDoors[2])
I’ve actually made this but i’ll try your script too, seems less complex and i guess it can do the exact thing i made here, now i’m trying to figure out how to correctly place the traps but thank you so much for the Table Solution