Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

frame does not become visible when button is clicked?

Asked by 1 year ago

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

Log in to vote
2
Answered by 1 year ago

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)
0
yes he is correct. you need to make the clients frame visible VictoreRoyale667 8 — 1y
0
Um, it still isn't working... The frame is still invisible and there is still no shop... MrBucketOfficial 39 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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

Answer this question