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 2 years 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

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

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years 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.

1local PlayerGui = script:FindFirstAncestorOfClass("PlayerGui")
2 
3script.Parent.MouseButton1Click:Connect(function()
4    PlayerGui.hui.ImageLabel.UploadTab.Visible = true
5end)
Ad

Answer this question