Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make all the plates come back at once?

Asked by 2 years ago

So an issue im currently having with my script is that when you remove everything past the wait(5) all the plates disappear at once like it should but when you add everything after the script breaks and only one of the plates disappears. Why is this and how can I fix this?

-- Plate Variables
local redplate = script.Parent.Plate.Red
local blueplate = script.Parent.Plate.Blue
local greenplate = script.Parent.Plate.Green
local yellowplate = script.Parent.Plate.Yellow
local platemodel = script.Parent.Plate

local platetable = {blueplate, greenplate, yellowplate, redplate}

--Simon Variables
local redsimon = script.Parent.Simon.Red1
local bluesimon = script.Parent.Simon.Blue1
local yellowsimon = script.Parent.Simon.Yellow1
local greensimon = script.Parent.Simon.Green1

--Main Script

while true do
    wait(10)
    r = platetable[math.random(#platetable)]
    r.Parent = script.Parent.PlateStorage
    for i, v in pairs(platemodel:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Transparency = 1
            v.CanCollide = false
            wait(5)
            v.Transparency = 0
            v.CanCollide = true
            end
        end
    end

1 answer

Log in to vote
0
Answered by 2 years ago

I figured this out on my own, the issue was that I put the wait statement in the loop instead of outside it. Heres the updated code.

while true do
    wait(7)
    r = platetable[math.random(#platetable)]
    r.Parent = script.Parent.PlateStorage
    _G.SimonActivate = true
    wait(3)
    for i, v in pairs(platemodel:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Transparency = 1
            v.CanCollide = false
        end     
    end
    wait(5)
    for i, v in pairs(platemodel:GetDescendants()) do
        if v:IsA("BasePart") then
            v.Transparency = 0
            v.CanCollide = true
            r.Parent = script.Parent.Plate
        end     
    end
end
Ad

Answer this question