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

ClickDetector MouseClick not working when running server?

Asked by 5 years ago

Hi,

I'm working on a game where the user clicks on certain objects, modals appear. I have it working when, in Roblox Studio, I choose "Play" or "Play Here". However, when I choose to "Start" a "Local Server", the modals do not appear when clicking on those objects.

Here's the code I am using to make a modal appear:

function onClicked(player) player.PlayerGui.GameConsoleGui.WelcomeModal.Enabled = true end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

The modals are ScreenGui objects that have "Enabled" set to false by default, and only have "Enabled" set to true by scripts.

Appreciate any help with this.

0
The server cannot access PlayerGui. Also it's Connect not connect. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You cannot access PlayerGui elements and edit them via a Script. You must use a local script. Just clone a local script to the player and have it run the function, and then have the script remove itself.

Have the server sided script as is, but clone a local script.

Have a client script that runs the code

wait(1)
player.PlayerGui.GameConsoleGui.WelcomeModal.Enabled = true
wait(0.1)
script:Destroy()
0
Thank you. I think I understand. Could you elaborate a little on how a server can clone a local script to a client? mrowredips 5 — 5y
0
Use a RemoteEvent from replicatedstorage, https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events seith14 206 — 5y
0
Awesome, thank you. Now that I have a better understanding of my original problem, I'm thinking it might just be easier if I use a LocalScript to do client-side detection that the object was clicked, and open the modals that way? There's no real need for me to involve the server in this transaction, is there? mrowredips 5 — 5y
0
Yep, I was able to get it to work with it all just LocalScripts. No need to involve the server. Thanks! mrowredips 5 — 5y
Ad

Answer this question