How to make a GUI open when clicking a Part

I honestly do not know here is the script inside the part:

local CLICK_BLOCK = script.Parent

local ITEM_ID = 2573844912

local player = game.Players:GetChildren()

local Click = Instance.new(“ClickDetector”,CLICK_BLOCK)

Click.MouseClick:connect(function(p)

if game:GetService(“GamePassService”):PlayerHasPass(player, ITEM_ID) then

game.StarterGui.AD1.Enabled = true

else

game:GetService(“MarketplaceService”):PromptPurchase(p,ITEM_ID)

end

end)

Here is the script inside the GUI button:

local ID = script.Parent.Parent.DecalID.Text

local Ad = game.Workspace.Advertisement1

local Decal = Ad.Sign.Decal

function leftClick()

Decal.Texture = ID

Ad.Sign.SurfaceGui.Enabled = false

end

script.Parent.MouseButton1Click:Connect(leftClick)

Someone tell me how to make these work please… I am really in need to do this!

4 Likes

You’re making something in the StarterGui visible and not something in the PlayerGui. StarterGui is on the server and it won’t replicate to the client. You need to fire a remote event to the client and in the client you would make the frame visible.

-- Server Script

remoteEvent:FireClient(player)

-- Local script

local frame = script.Parent.Frame
remoteEvent.OnClientEvent:Connect(function()
    frame.Visible = true
end)

Ah yes, but it is most likely he is trying to do it for the local player. Correct me if I’m wrong @BlueTechnician. I think it’s a mistake instead.

I have never done a remote Event in my life so I may need a guide to it…

I am trying to do it local so it only shows for the player that clicked the part.

But then for the second script I want it to be server wide.

My bad, I read your reply wrong. Yes you would need to fire a remote from the part to the local script in the GUI

How would I do that? I have never done this before…

First off, there is no property called Enabled on a frame. It’s called Visible not ‘Enabled’.

Create a remote event in replicated storage and add a variable to access it.

(Do this in your server script)

local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent

Inside your code you would do (replacing the line where you make the frame visible):

remoteEvent:FireClient(player)

This tells the server to update the player’s GUI, which we will do in a local script.

Now open up your local script and add the following:

local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent
local frame = script.Parent.Frame -- or wherever your frame is at

remoteEvent.OnClientEvent:Connect(function()
     frame.Visible = true
end)

@AdvancedDrone actually I selected the ScreenGui not the frame.

StarterGui is a container for holding interfaces that replicate to the client on respawn. It’s static. Regardless of whether its for the client or server, nothing there is visible. All seen Guis are from PlayerGui or an adornee to a supported location, such as the workspace.

Here is a very nice tutorial on Remote Events:

Credits to the person who made that video

Additionally, here is the source for the RemoteEvent
RemoteEvent | Documentation - Roblox Creator Hub.

I would suggest having a good read, and watching that video to understand fully what a remoteEvent is.

Thank you so much everyone who helped out.

Mhm, it’s still not working… Should I export it to a blank place and send the place to you guys to see if you can see what might not be working? @histo_rical @colbert2677 @AdvancedDrone

No. I’m sure that it does work, your implementation is just faulty or misunderstood. What is the code and hierarchy of objects you’re working with? Scripting Support is for helping you learn, not spoonfeeding you code without explanation or place files.

Scripts That Need to Be Fixed.rbxl (25.8 KB)

I mean I wanted to see if you guys could help me understand what I did wrong that I should learn to correct…

Local Script inside gui:

local remoteEvent = game:GetService(‘ReplicatedStorage’).RemoteEvent
local frame = script.Parent.Frame – or wherever your frame is at

remoteEvent.OnClientEvent:Connect(function()
frame.Enabled = true
end)

Code inside part:
local remoteEvent = game:GetService(‘ReplicatedStorage’).RemoteEvent

local CLICK_BLOCK = script.Parent

local ITEM_ID = 2573844912

local player = game.Players:GetChildren()

local Click = Instance.new("ClickDetector",CLICK_BLOCK)

Click.MouseClick:connect(function()

if game:GetService("GamePassService"):PlayerHasPass(player, ITEM_ID) then

remoteEvent:FireClient(player)

else

game:GetService("MarketplaceService"):PromptPurchase(p,ITEM_ID)

end

Your method to work out the player isn’t accurate, you’re using a table value (game.Players:GetChildren()). You’ll need to figure out whose actually clicking it and make that value the player.

local remoteEvent = game:GetService(‘ReplicatedStorage’).RemoteEvent
local CLICK_BLOCK = script.Parent
local ITEM_ID = 2573844912
local Click = Instance.new("ClickDetector",CLICK_BLOCK)

Click.MouseClick:connect(function(player)
    if game:GetService("GamePassService"):PlayerHasPass(player, ITEM_ID) then
       remoteEvent:FireClient(player)
    else
        game:GetService("MarketplaceService"):PromptPurchase(p,ITEM_ID)
    end
end)

The reason it isn’t working is because you didn’t create a remote event in ReplicatedStorage.

Also you’re missing an end) in the scripts in workspace in the Advertisements model.