#Proximity prompt only opens GUI 50% of the time when testing with 0 changes made

1 messages · Page 1 of 1 (latest)

humble scarab
#

When interacting with the proximity prompt when play testing it'll either work or it won't. I don't change the code or anything it just decides when it feels like it ig

nimble dew
# humble scarab

maybe you need to add WaitForChild() when your setting your intro and Teleportbuttons variables

nimble dew
# humble scarab

also bro please compact your teleport button logic into a for loop

humble scarab
#

I have no idea what a for loop is 💔

tepid hollyBOT
#

studio** You are now Level 1! **studio

humble scarab
#

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

woven marsh
#

Any errors?

woven marsh
nimble dew
humble scarab
#

Y'know maybe I should've checked that

nimble dew
#

so you don't repeat yourself

humble scarab
nimble dew
# humble scarab

What do the variables like "teleport1" or "teleport2" passed in the last three functions do?

humble scarab
#

absolutely nothing

nimble dew
#

okay

humble scarab
#

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

nimble dew
# humble scarab I have no idea what a for loop is 💔

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
humble scarab
#

Ok nevermind I wasn't using waitforchild properly I think

#

This should be the correct way to set this up right?

nimble dew
#

yes

humble scarab
#

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

nimble dew
#

that works fine

nimble dew
humble scarab
humble scarab
nimble dew
humble scarab
nimble dew
#

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

humble scarab
#

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?

nimble dew
#

and saying "for Button in TeleportButtons:GetChildren()", basically this will be the name of the child when you work with it

humble scarab
#

Alright thanks a ton VVbanana

nimble dew
#

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

humble scarab
#

How would you reference an individual value in the index?

tepid hollyBOT
#

studio** You are now Level 2! **studio

nimble dew
#

like if I wanted to Print a certain index of the list without looping through it

humble scarab
#

Like if I just wanted it to fetch "Grape" would that be better done with a different outside function?

nimble dew
#

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

#

@humble scarab , is Luau (Roblox's coding language) your first ever coding language?

humble scarab
#

Yeah

#

I've very lightly messed around with C# but never got much further than a few lines in a few tutorials

nimble dew
#

Okay, if your ever interested in other languages just know that lua is basically the only language that has indexes that start at 1

nimble dew
#

in another language

humble scarab
#

I tried to write it myself and tinker with it a bit but even when I copy the code exactly it doesn't work

nimble dew
#

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
tepid hollyBOT
#

studio** You are now Level 6! **studio

nimble dew
#

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

humble scarab
nimble dew
#

okay change the if statement to
"if Button.Name == "T1" then"

humble scarab
#

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

nimble dew
#

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

humble scarab
#

removing the i, at the start didn't change anything

humble scarab
#

I'll try experimenting with it further and figuring out a way to format it on my own