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

GUI Text Button Not Appearing On Event?

Asked by 2 years ago
Edited 2 years ago

This is a LocalScript I have for a leave button GUI when you teleport somewhere, you're supposed to touch a wall, get teleported and you can press the GUI to leave, but the GUI isn't appearing when I teleport. (LocalScript in StarterPlayerScripts)

game.StarterGui:WaitForChild("LeaveButtonGUI")
game.StarterGui.LeaveButtonGUI:WaitForChild("LeaveButton")
game.Workspace:WaitForChild("InsideContent")
game.Workspace.InsideContent:WaitForChild("TPWallLeft")
game.Workspace.InsideContent:WaitForChild("TPWallMiddle")
game.Workspace.InsideContent:WaitForChild("TPWallRight")

local LBGUIB = game.StarterGui.LeaveButtonGUI.LeaveButton
local TPWallLeft = game.Workspace.InsideContent.TPWallLeft
local TPWallRight = game.Workspace.InsideContent.TPWallRight
local TPWall Middle = game.Workspace.InsideContent.TPWallMiddle
local Player = game:WaitForChild("Players").LocalPlayer

Player.CharacterAdded:Connect(function(Character)
    local HRP = Player.Character:WaitForChild("HumanoidRootPart")
    TPWallLeft.Touched:Connect(function(LeaveButtonAppear)
        LBGUIB.Visible = true
    end)
end)

If I do it to the player's GUI it still doesn't do anything

game.StarterGui:WaitForChild("LeaveButtonGUI")
game.StarterGui.LeaveButtonGUI:WaitForChild("LeaveButton")
game.Workspace:WaitForChild("InsideContent")
game.Workspace.InsideContent:WaitForChild("TPWallLeft")
game.Workspace.InsideContent:WaitForChild("TPWallMiddle")
game.Workspace.InsideContent:WaitForChild("TPWallRight")

local Player = game:WaitForChild("Players").LocalPlayer
Player.PlayerGui:WaitForChild("LeaveButtonGUI")
local LocalPlayer = game:GetService("Players").LocalPlayer
local LeaveButton = LocalPlayer.PlayerGui.LeaveButtonGUI.LeaveButton
local LBGUIB = game.StarterGui.LeaveButtonGUI.LeaveButton
local TPWallLeft = game.Workspace.InsideContent.TPWallLeft
local TPWallRight = game.Workspace.InsideContent.TPWallRight
local TPWall Middle = game.Workspace.InsideContent.TPWallMiddle

Player.CharacterAdded:Connect(function(Character)
    local HRP = Player.Character:WaitForChild("HumanoidRootPart")
    TPWallLeft.Touched:Connect(function(LeaveButtonAppear)
        LeaveButton.Visible = true
    end)
end)
0
use print statements for every line, and tell me where it gets to. JesseSong 3916 — 2y
0
Maybe the character is already added before all the waitforchilds are finished. Because the character is already added, the function wont do anything. JustinWe12 723 — 2y
0
I fixed it a while ago SuperSM1 67 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

You are editing the StarterGui's buttons, you need to use the localplayer's ui buttons

(also you can use "workspace" instead of "game.Workspace")

local LocalPlayer = game:GetService("Players").LocalPlayer

local LeaveButtonGUI = LocalPlayer.PlayerGui.LeaveButtonGUI
-- fix up the rest of the code to use the variable above, everything else works fine i assume
0
Tried it and it says that LeaveButtonGUI isn't a valid member of the player gui, think it's cuz the code runs before it can load, problem is, i dunno how to get it to waitforchild, it's not an object that's already there even when it's not running SuperSM1 67 — 2y
0
Nevermind, I got it to stop erroring but it's still not doing anything SuperSM1 67 — 2y
Ad

Answer this question