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

How do I make my click detector script work for gui enabling?

Asked by 5 years ago

I put a click detector in a part. When I click the part I want a specific screen GUI to enable itself

My Script.

function Clicked(Plr)
print(Plr)
Plr.PlayerGui:WaitForChild("BookGui").ImageLabel.Visible =true
Plr.PlayerGui.BookGui.TextButton.Visible =true

end

the error I get is BookGui isn't a part of PlayerGui but it is! When I go in test mode its there.

2 answers

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

Errors: You can not access the PlayerGui because Gui's are set by the client. Maybe some Gui's created by the server you can access but most of the Gui's that we use is created with client.

You need to use RemoteEvents with FireClient

You can see RemoteEvents and FireClient on roblox wiki:

RemoteEvents/RemoteFunctions

FireClient

For this, you need to create a Remote Event, LocalScirpt, ClickDetector & Script

For first create a RemoteEvent and put it on Replicated Storage, now create a LocalScript and put it on StarterGui, on LocalScript located in StarterGui put this code:


-- FOR USE THIS PUT IN StarterGui -- repeat wait() until game.Players.LocalPlayer -- Not return nil for player local event = game:GetService("ReplicatedStorage"):WaitForChild("Event") -- Put your event here local plr = game.Players.LocalPlayer -- Get player event.OnClientEvent:Connect(function() -- On fire the client local gui = "BookGui" -- Put your GUI Name here plr.PlayerGui:WaitForChild(tostring(gui)) -- Wait for GUI if plr["PlayerGui"]:FindFirstChild(tostring(gui)) then -- Find gui local gui = plr["PlayerGui"][tostring(gui)] gui.ImageLabel.Visible = true -- set ImageLabel visibility to true gui.TextButton.Visible = true -- Set TextButton visibility to true end end)

Or you can put it on GUI and put this code:


-- FOR USE THIS PUT IN YOUR GUI -- wait() local event = game:GetService("ReplicatedStorage"):WaitForChild("Event") -- Put your event here event.OnClientEvent:Connect(function() -- On fire the client script.Parent.ImageLabel.Visible = true -- set ImageLabel visibility to true script.Parent.TextButton.Visible = true -- Set TextButton visibility to true end)

Now create a Script and ClickDetector In your part and put this:

local event = game:GetService("ReplicatedStorage"):WaitForChild("Event") -- Put your event here

local clickdetector = script.Parent.ClickDetector -- Click detector location

clickdetector.MouseClick:Connect(function(plr)
    event:FireClient(plr)
end)

Hope it helped!

0
Oh my god it works ! Thank you so much HeadlessGuide 16 — 5y
Ad
Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

You got that error, cuz you can't access to player's stuff from script(server script). If you want to do that, you need to use remote events. It is very easy.

For first insert RemoteEvent in ReplicatedStorage and change it name what you want. Now type this into ur clickdetector script

local Event = game:GetService("ReplicatedStorage"):WaitForChild("Your Event Here") --your remote event name here

function Clicked(player)
    Event:FireClient(plr) --giving exept player info that he clicked on the part
end

script.Parent.MouseClick:Connect(Clicked)

Now insert a localscript into startergui and type in

local Event = game:GetService("ReplicatedStorage"):WaitForChild("Your Event Here") --your remote event name here
local player = game.Players.LocalPlayer

Event.OnClientEvent:Connect(function() --this script starts when he get info from server
    player.PlayerGui:WaitForChild("BookGui").ImageLabel.Visible =true
    player.PlayerGui.BookGui.TextButton.Visible =true
end)
0
The script isn't doing anything.. I don't get my gui popping up or an error in output. HeadlessGuide 16 — 5y
0
then you did something wrong HaveASip 494 — 5y
0
Does the local script go inside the BookGui thats in startergui or just inside startergui HeadlessGuide 16 — 5y
0
No, you can put it in bookgui HaveASip 494 — 5y
View all comments (11 more)
0
the local script inside the click detector has plr underlined where it says Event:FireClient(plr) HeadlessGuide 16 — 5y
0
in clickdetector script do you have 7 line? HaveASip 494 — 5y
0
only 6 HeadlessGuide 16 — 5y
0
re-check and do what I said. Maybe you did somthing wrong HaveASip 494 — 5y
0
I tested it myself in its working HaveASip 494 — 5y
0
line 4 on clickdetector script is (plr) supposed to be underlined in orange HeadlessGuide 16 — 5y
0
0
Ive written down the scripts myself rather then copying them and I filled in my events name in the place it says to but still no error in output and no gui showing HeadlessGuide 16 — 5y
0
What if I take bookgui out of startergui and put it in the workspace and then use game.workspace to find the path? HeadlessGuide 16 — 5y
0
Change a localscript in ClickDetector to normal HaveASip 494 — 5y
0
thanks for helping HeadlessGuide 16 — 5y

Answer this question