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

ImageButton In SurfaceGui Doesnt Show Frame When Activated?

Asked by 1 year ago

im making a script once the button is pressed, a framegui becomes visible once its pressed, the surfacegui is in ScreenGui adorneed to a part, but for some reason the script doesn't work

Script In Button In SurfaceGui In StarterGui

game:GetService("Players").PlayerAdded:Connect(function(plr)
script.Parent.MouseButton1Click:Connect(function()
    plr.PlayerGui.hui.ImageLabel.UploadTab.Visible = true
    end)
end)

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

The script gets put into the player's PlayerGui after the player joins the game; therefore, the PlayerAdded event will not fire for that player, as the player is already in the game before the script is created.

As the script is a descendant of the PlayerGui, you can use the FindFirstAncestorOfClass method to get the player's PlayerGui.

local PlayerGui = script:FindFirstAncestorOfClass("PlayerGui")

script.Parent.MouseButton1Click:Connect(function()
    PlayerGui.hui.ImageLabel.UploadTab.Visible = true
end)
Ad

Answer this question