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

Trouble making it so my script can be run multiple times before cooldown. How would I fix this?

Asked by
Galvek 0
3 years ago

So I am having a pretty simple issue with my game

Client Side Script:

local Stage1Parts = game.Workspace:WaitForChild("Stage1")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Stage1Fire = ReplicatedStorage.Stage1Fire
local activated = false

for i,v in pairs(Stage1Parts:GetChildren()) do 
    v.Touched:Connect(function (hit)
        if activated == false then
            if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
                activated = true
                Stage1Fire:FireServer(v)
                print("Stage1Fire Fired to Server")
                wait(1)
                activated = false
            end
        end
    end)
end

Server Side Script:

local Stage1Parts = game.Workspace:WaitForChild("Stage1")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Stage1Fire = ReplicatedStorage.Stage1Fire
local Activated = false

local function Stage1PartFunction(player,value)
    if Activated == false then
        Activated = true
        for i,v in pairs(value:GetChildren()) do
            v.Transparency = 0
            v.CanCollide = true
        end    
        wait(8)
        for i,v in pairs(value:GetChildren()) do
            v.Transparency = 0.8
            v.CanCollide = false
        end
        Activated = false
    end
end

Stage1Fire.OnServerEvent:Connect(Stage1PartFunction)

So this scripts purpose is to make certain blocks transparent and non colliding when you hit the corresponding buttons. The system works great but I have this issue were I don't know how to make it so you can activate multiple buttons at the same time. For example: If I press Button 1 then I have to wait for its whole cycle to be finished before I can press button 2 I can't figure out how to fix this

Answer this question