Fixing scripts for a GUI that opens via a ClickDetector on a model?
Asked by
3 years ago Edited 3 years ago
I've tried practically everything to fix this, but I can't seem to get it working.
I want to have a book-style GUI (done via RoDocker) become visible for the player who clicked on a model in my game. However, while the ClickDetector works, the scripts don't seem to and the GUI never becomes visible.
I'm doing this via a RemoteEvent. I want the ClickDetector to fire the RemoteEvent so the Client side knows to make the GUI visible. I've tried more than just this method, but nothing seems to be working.
My question is a lot similar to this one from 2020 on the Dev Forum, but it was never solved and I really don't want to make the book a tool.
I'm autistic and rather new to Lua (with some knowledge in other languages), so please be patient with me. I'll need a lot of help.
Here are the placements of my scripts:
https://i.imgur.com/vW27kLe.png (My ClickDetector in its parent model, with its script to tell the RemoteEvent to fire)
https://i.imgur.com/qwJ09Bz.png (My RemoteEvent in ReplicatedStorage)
https://i.imgur.com/SoFMCzS.png (My script to tell the GUI to become visible "MakeVisible" in the GUI I want to make visible, note how RoDocker handles book GUIs via placing multiple frames into one ScreenGui)
My scripts so far are below. I've changed these so many times to try to get these to work, so they may look wonky from all the things I ended up trying.
Script telling RemoteEvent to fire (DinosaurBookOpen):
1 | local clickDetector = workspace.DinosaurClickDetector |
3 | local remoteEvent = ReplicatedStorage:WaitForChild( "DinosaurBook" ) |
5 | local function onClicked(player) |
6 | remoteEvent:FireClient(player) |
9 | clickDetector.MouseClick:Connect(onClicked) |
Script receiving RemoteEvent and telling GUI to becoming visible (MakeVisible):
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
3 | local remoteEvent = ReplicatedStorage:WaitForChild( "DinosaurBook" ) |
5 | local function onNotifyPlayer() |
6 | script.Parent.Visible = = true |
9 | remoteEvent.OnClientEvent:Connect(onNotifyPlayer) |