#Proximity prompt only opens GUI 50% of the time when testing with 0 changes made
1 messages · Page 1 of 1 (latest)
maybe you need to add WaitForChild() when your setting your intro and Teleportbuttons variables
also bro please compact your teleport button logic into a for loop
I have no idea what a for loop is 💔
** You are now Level 1! **
But I will try this
I am incredibly new to scripting and this is my first project so I'm just crash coursing my way through this until I have something functional
Any errors?
Vro beo
Basically you can loop through each of the buttons in the TeleportButtons Frame and make your code much shorter
Y'know maybe I should've checked that
so you don't repeat yourself
What do the variables like "teleport1" or "teleport2" passed in the last three functions do?
absolutely nothing
okay
I have them there incase I need to reference them later
WaitForChild seemingly didn't do anything, tried putting it on the promptS value and rig still isn't considered a valid member of the folder
You can replace the last three functions in the script screenshot you sent to this:
--Teleporting Buttons
for Button in TeleportButtons:GetChildren() do
--Skip past the "Close" gui button
if Button == TeleportButtons.Close then
continue
end
--Teleport Logic
Button.Activated:Connect(function()
TeleportButtons.visible = false
if Button == TeleportButtons.T1 then
plr:MoveTo(Vector3.new(-209, 0.5, 0))
else
plr:MoveTo(Vector3.new(0, 40.5, 0))
end
sound:Play()
menuactive = false
end)
end
Ok nevermind I wasn't using waitforchild properly I think
This should be the correct way to set this up right?
yes
The error stopped happening and it works now after I did this but I wanna know if this is the best way to go about it
that works fine
also for someone new to scripting your scripts are very organized and easy to read which is great
Thank you for this I will definitely start doing this from now on
Thank you again
I try for my own sake so debugging isn't nearly as hard as it was the first few times
whenever you have anything that looks super repetitive or has like a pattern to it you can always use for loops and arrays to help you code faster and easier
Do you mind explaining how the "for Button in TeleportButtons" part works? I can get how the rest of it works but what does this line do?
I actually changed it to "for Button in TeleportButtons:GetChildren()" because before what I wrote would cause an error
but basically
TeleportButtons:GetChildren(), it returns a list of every "Child" of it
so this
if I were to do Baseplate:GetChildren() and I printed that
it would print this "{Part1, Part2}"
and when you use a for loop you can go through all of these and do whatever you want with them
So adding the Button value creates a variable you can reference to then fetch each individual button for example in the code you just provided?
and saying "for Button in TeleportButtons:GetChildren()", basically this will be the name of the child when you work with it
yes
Alright thanks a ton 
but Button only represents one "Child" at a time
what you can also do is "for i, Button in TeleportButtons:GetChildren()"
that "i" variable stands for Index
and lemme make an example real quick
local GroceryList = {
"Strawberry", -- Index 1
"Grape", -- Index 2
"Watermelon" -- Index 3
}
for Index, Grocery in GroceryList do
print("Item " .. Index, " in the list is " .. Grocery)
end
so basically this shows the Index and Value of an Array
and what I'm doing is printing the index and value into something that a person could better understand, and if you were in real life and given a grocery list, and asked to read for example, the 2nd item on the list (A grape), the computer can do the same thing by looking at the 2nd index of the array, and printing it
and what this prints is this
How would you reference an individual value in the index?
** You are now Level 2! **
?
like if I wanted to Print a certain index of the list without looping through it
Like if I just wanted it to fetch "Grape" would that be better done with a different outside function?
if I wanted to fetch Grape you could do
local Grape = GroceryList[2]
you can use indexes to individually search something up in an array
and btw an Array in like normal terms is just a list of stuff
and there are tons of things you can do with it
@humble scarab , is Luau (Roblox's coding language) your first ever coding language?
Yeah
I've very lightly messed around with C# but never got much further than a few lines in a few tutorials
Okay, if your ever interested in other languages just know that lua is basically the only language that has indexes that start at 1
so this would turn into this
local GroceryList = {
"Strawberry", -- Index 0
"Grape", -- Index 1
"Watermelon" -- Index 2
}
for Index, Grocery in GroceryList do
print("Item " .. Index, " in the list is " .. Grocery)
end
in another language
Back on this it's spitting out an error about activating the buttons
I tried to write it myself and tinker with it a bit but even when I copy the code exactly it doesn't work
try replacing the code with this
--Teleporting Buttons
for i, Button in TeleportButtons:GetChildren() do
--Skip past the "Close" gui button
if Button == TeleportButtons.Close then
continue
end
--Teleport Logic
Button.Activated:Connect(function()
TeleportButtons.visible = false
if Button == TeleportButtons.T1 then
plr:MoveTo(Vector3.new(-209, 0.5, 0))
else
plr:MoveTo(Vector3.new(0, 40.5, 0))
end
sound:Play()
menuactive = false
end)
end
** You are now Level 6! **
cause I think it's get the indexes and not the button themselves
also typically if you don't plan on using indexes in your code like in this case instead of
for i, Button in TeleportButtons:GetChildren() do
you could replace it with
for _, Button in TeleportButtons:GetChildren() do
cause you don't plan on working with the index
also I gtg sorry JTP, if you need help try chatgpt to POINT you in the right direction, or ask others for help
Now it isn't giving the error but it isn't teleporting the player
okay change the if statement to
"if Button.Name == "T1" then"
I thought maybe the part for skipping the close button was somehow clogging it up and blocking the teleporting but nothing changed
Still isn't working
I'm sorry JTP but I got to go, you could try using Chatgpt, simply remove the if statement, or revert back to the three function thing
removing the i, at the start didn't change anything
Alright it's all good, you've already helped a ton
I'll try experimenting with it further and figuring out a way to format it on my own
that's great