#Super Laggy button press

1 messages · Page 1 of 1 (latest)

wintry gulch
#
    
    print("Activated")
    if showing == true then

        for i, Land in ipairs(LandInstances:GetChildren()) do

            if Land.Name == "Land" then
                showing = false
                
                local GUI = Land:FindFirstChild("SurfaceGui")
                
                if GUI then

                    GUI.Enabled = false
                end

            end


        end

    elseif showing == false then
        print(showing)
        for i, Land in ipairs(LandInstances:GetChildren()) do
            print("in loop")
            if Land.Name ~= "StartingLand1" or "StartingLand2" then
                showing = true
                print("in if 1")
                print(Land)
                local GUI = Land:FindFirstChild("SurfaceGui")
                
                if GUI then

                    GUI.Enabled = true
                end

            end

        end

    end
    task.wait(.1)
    
end)
``` causes like ALOT of un-needed
 runs (prints ALOT from 1 click)
jolly stag
wintry gulch
#

whoops

#

good point

#

but still why is it so laggy

jolly stag
#

cuz many objects in it

wintry gulch
#

im just looping through a folder w like 30 instances

wintry gulch
#

34 isint alot

jolly stag
#

then it shouldnt lag

#

maybe because ur looping inside of a loop inside of a loop 34 times

wintry gulch
#

where ius the double loop

#

theres two loops inside conditionals

#

1 in each

jolly stag
#

then it hsouldnt lag

unkempt crystal
#

im going to assume this but im pretty sure .Activated can be repeated if its in like a function that gets called many times or whatever

#

so add like a nil value

local connection
connection=blahblah.Activated:Connect(function()
    connection:Disconnect()
end)```
#

you can try to do something like that

wintry gulch
#

didnt work

unreal oasis
#

BUTTONLandOpen.Activated:Connect(function()
    
    print("Activated")
    if showing == true then

        for i, Land in ipairs(LandInstances:GetChildren()) do

            if Land.Name == "Land" then
                showing = false
                
                local GUI = Land:FindFirstChild("SurfaceGui")
                
                if GUI then
                    GUI.Enabled = false
                end
            end
        end

    elseif showing == false then
        showing = true
        print(showing)
        for i, Land in ipairs(LandInstances:GetChildren()) do
            print("in loop")
            if Land.Name ~= "StartingLand1" and Land.Name ~= "StartingLand2" then
                print("in if 1")
                print(Land)
                local GUI = Land:FindFirstChild("SurfaceGui")
                
                if GUI then
                    GUI.Enabled = true
                end
            end
        end
    end
    task.wait(.1)
    
end) ```
#

@wintry gulch

#

or skipping all of that and you can just change this code because that might seem causing the problem

if Land.Name ~= "StartingLand1" or "StartingLand2" then

#

change that code to this

if Land.Name ~= "StartingLand1" and Land.Name ~= "StartingLand2" then

wintry gulch
#

I’ll try it when I’m at my pc though

#

I mean stuff prints 100x a second

#

so every millisecond

#

I’m assuming

unreal oasis
#

the code line i provided correctly checks that the name is StartingLand1 and is not StartingLand2 which it like properly filters out those two lands and only processing the ones you actually want

#

@wintry gulch

wintry gulch
#

Ok I’ll read this there morning ty

unreal oasis
wintry gulch
#

so would I need another ~= your saying?

#

or not?

unreal oasis
#

yes yes i’m sorry i was just filling those up

wintry gulch
#

ooh alright

#

I’ll try that

unreal oasis
#

yeaaa

#

alright

wintry gulch
#

probably will work

#

I’m just confused on how that caused a lot of activations even though there’s only 36 pieces of land

unreal oasis
#

alright alright

unreal oasis
unreal oasis
#

@wintry gulch

#

did it work?

wintry gulch
unreal oasis
tiny pathBOT
#

studio** You are now Level 4! **studio

unreal oasis
#

what did you put?

wintry gulch
#

think i fixed it

#

maybe

#

there was a remote event firing

#

that caused a chain

#

nvm

#

ok now that works fine but

#

i have this which loads the users land

#

wait

#

got cut ioff

wintry gulch
#

this was the reaosn

#

just found other struff too

unreal oasis
#

of course

#

glad to help

#

so it did work right

wintry gulch
#

i also accidentally created a chain by misplacing my remote event on the server

#

so it loops

#

Fine

unreal oasis
#

ahhh

#

alright man

wintry gulch
#

Then it triggered thatmlooop causing the event and the event caused more loops

unreal oasis
#

ahh

#

alright man

#

but i’m glad to help

wintry gulch
#

yeah thank u sm dude