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)
#Super Laggy button press
1 messages · Page 1 of 1 (latest)
cuz ur looping inside land
oooh
whoops
good point
but still why is it so laggy
cuz many objects in it
im just looping through a folder w like 30 instances
then it shouldnt lag
maybe because ur looping inside of a loop inside of a loop 34 times
how
where ius the double loop
theres two loops inside conditionals
1 in each
then it hsouldnt lag
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
hmm ill try this
didnt work
try this if you haven’t already fixed it copy the code you have right now and save it somewhere
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
how would that be causing the lag
I’ll try it when I’m at my pc though
I mean stuff prints 100x a second
so every millisecond
I’m assuming
because since StartingLand2 is a non empty string that it’s always truthy so that condition always evaluates to true no matter what the land name is
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
Ok I’ll read this there morning ty
alright!
ok this is weird bc I’m checking if the .Name of land is NOT StartingLand1 or StartingLand2 (everything else is named land with a ID)
so would I need another ~= your saying?
or not?
yes yes i’m sorry i was just filling those up
probably will work
I’m just confused on how that caused a lot of activations even though there’s only 36 pieces of land
alright alright
it’s not that the button is being clicked multiple times it’s just that one click is doing way more work than it’s intended to do because it processing land it should be skipping
no
it didn’t work?
** You are now Level 4! **
what did you put?
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
oh yes
this was the reaosn
just found other struff too
tysm
yes it was part of the issue
i also accidentally created a chain by misplacing my remote event on the server
so it loops
Fine
Then it triggered thatmlooop causing the event and the event caused more loops
yeah thank u sm dude