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