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

How to open GUI when clicking a part?

Asked by 4 years ago

Hello, I'm trying to make a script that will make a GUI in StarterGUI appear (Changing the visibility to true) when a player clicks a part in Workspace.

Here is my script:

script.Parent.Parent.Parent.Parent.ClickDetector.MouseClick:Connect(function()

    game.StarterGui.VehicleSelctionGUI.Frame.Visible = true

end)

1 answer

Log in to vote
0
Answered by 4 years ago

PlayerGui


When a player joins the game, all of the contents inside StarterGui are locally cloned into that player's PlayerGui, so if you want to mess around with the guis of a specific player, it would be best to run your code on a localscript, as MouseClick replicates and the first parameter of MouseClick is the player who clicked.

So, you can match the player who clicked with the localPlayer to see if the localplayer is the one who clicked the button.

--Localscript (Preferably inside VehicleSelctionGUI.Frame)
local Part = --Whatever part you are using
local Player = game.Players.LocalPlayer

Part.ClickDetector.MouseClick:Connect(function(plr)
    if plr == Player then
        script.Parent.Visible = true --if this isnt in VehicleSelctionGUI.Frame, reference it directly
    end
end)

Hopefully this helped!

0
Thank you i'll try this out! GodsGraceSavesAll 6 — 4y
0
Thank you so much it works! GodsGraceSavesAll 6 — 4y
Ad

Answer this question