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

frame does not become visible when button is clicked?

I am making a game and i have a button that should open a shop, and the code I used is in a local script, but whenever i lcick on the button, it doesn't open. I have a clickdetector in the button, and no errors happen in output. Any idea on how to fix this?

clicker = script.Parent.ClickDetector
shop = game:GetService("StarterGui").Shop.Frame

function onClick(player)
	shop.Visible = true
end

clicker.MouseClick:Connect(onClick)

Button: https://imgur.com/a/6mrRNNp

2 answers

hiya!

you're code won't produce any errors as it is making the frame visible, yes, but it's not making the client's frame visible.

all the contents of StarterGui are replicated into the client's PlayerGui, which is where you should be changing the visibility of the frame, not in StarterGui

a fix for your code would be the following:

clicker = script.Parent.ClickDetector
shop = game:GetService("StarterGui").Shop.Frame

function onClick(player)
    -- get the player's PlayerGui, get the Shop Gui and then the Frame
    local PlayerFrame = player.PlayerGui:WaitForChild('Shop').Frame
    PlayerFrame.Visible = true
end

clicker.MouseClick:Connect(onClick)

2 comments

0

yes he is correct. you need to make the clients frame visible

0

Um, it still isn't working... The frame is still invisible and there is still no shop...

If you are using a part to run this you'll need to create an event as this isn't turning the UI on the player's screen visible.

local replicated = game:GetService("replicatedstorage")
function onClick(player)
    replicated.event:FireClient(player)
end
local replicated = game:GetService("replicatedstorage")
replicated.event.OnClientEvent:Connect(function()
	Player.PlayerGui.Visible = true
end)

or something like that you cant change a players screen through a service script only local so you use a server script to fire a client even which then makes the player who receives it screen change

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