Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ImageButton In SurfaceGui Doesnt Show Frame When Activated?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.