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)
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)