Take note: This answer assumes you have experience with remotes, so explanations on remotes wont be very well touched on, same with Filtering Enabled.
There's a few things I noticed when looking at your code.
You're trying to access a player's PlayerGui via a server script. (Or just a Script :P) The server's not able to mess with what's in a player's PlayerGui. (A feature of FE)
What's OnTouched in the client script? (Or LocalScript)
Why's the client prompting the server so that the server opens the gui? Why not have the server prompt the client instead?
The Solution
Based upon my question in point #3, this would be a much better approach than having the server handle stuff on the client. Here's an example of what I mean:
local ClientRemote = game.ReplicatedStorage.Remote
local Part = script.Parent
local Debounce = true
Part.Touched:Connect(function(Hit)
if Debounce and Hit.Parent and Hit.Parent:FindFirstChild('Humanoid') then
Debounce = false
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
ClientRemote:FireClient(Player)
end
wait(2)
Debounce = true
end
end)
Okay, now we're all finished! :D Now TV, here I come!
Stop right there! What about the client?
Oh yeah...
Now, for the client, we can now set up for it to listen for when it's being prompted.
local ClientRemote = game.ReplicatedStorage.Remote
local Gui = script.Parent
function OpenGui()
Gui.Enabled = true
end
ClientRemote.OnClientEvent:Connect(OpenGui)
And now we're done! :D
Stop right there, TheeDeathCaster! Aren't you forgetting something?
Oh, right. Forgot. lol
Stuff touched on, but was never really explained.
GetPlayerFromCharacter - A function that returns the player if what was given it was a player's character, if not it will return nil.
Debounces - A way to prevent code from firing multiple times upon execution.
If you have any questions, please don't hesitate to let me know. ^^
I hope this helped! :D
Edit
Being pointed out in the community chat, the original script's changing the visibility of a Frame and not ScreenGui. >~< Sorry about that.
To make this edit is fairly simple; you just gotta change up how I set up the client script; for example, changing Gui from being defined towards the ScreenGui, it would be changed to be defined as the Frame, and .Enabled would be switched out with .Visible.
Here's edits made to the script to show what I mean:
local ClientRemote = game.ReplicatedStorage.Remote
local Gui = script.Parent.Frame
function OpenGui()
Gui.Visible= true
end
ClientRemote.OnClientEvent:Connect(OpenGui)
Again, if you have any questions, please don't hesitate to let me know. : )
2 comments
I apologize if this answer isn't the best. I haven't answered a question in a lil' while.
I did not work? Why?