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

How do you access the player [player gui] in filtering enabled mode?

Asked by
Scaii_0 145
6 years ago

What I am trying to accomplish is, on touch, a GUI is replicated into the player GUI from server storage. I have done this without FE but I am looking to find out how to do it with FE.

On touch how would I get from the character to the player? And then their player GUI?

Would i have to use Remote Functions/Events or will something more simple like:

function onTouch(Humanoid) h=~nil then GetPlayerFromCharacter

will something like that do?

2 answers

Log in to vote
0
Answered by
mraznboy1 194
6 years ago

You would have to use a remote function. The server side would handle the part where it detects the touch:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent --name this whatever you'd like, and place it in the Replicated Storage, as both the Client and Server can access it.

function onTouch(hit)
    if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
         RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
    end
end

script.Parent.Touched:connect(onTouch)

This fires the event that lets the client do whatever is connected to the event. This connection would be defined in a LocalScript. You can place it in the StarterPlayerScripts or somewhere similar where localscripts can run:

local RemoteEvent = game.ReplicatedStorage.RemoteEvent --again, make sure this name matches up to the RemoteEvent you're firing in the server script.
local player = game.Players.LocalPlayer

function ShowGui()
    local gui = game.ReplicatedStorage.GUI_NAME:clone() --whatever you called it
    if (not player.PlayerGui:FindFirstChild(gui.Name)) then
        gui.Parent = player.PlayerGui
    end
end

RemoteEvent.OnClientEvent:connect(ShowGui)
1
Thank you for the introduction on FE. You taught me what no other roblox tutorial video could. I checked the wiki so do have a basic underrstanding but didn't know how to use it. Scaii_0 145 — 6y
0
No problem! It's very easy, just make sure to keep everything organized or you can easily lose yourself. mraznboy1 194 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You don't need to use remote events. You can do everything in the server script.

-- In a server script within the part being touched
local part = script.Parent

part.Touched:connect(function(otherPart)
    if otherPart.Parent then
        local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
        if player and not player.PlayerGui:FindFirstChild("ScreenGui") then
            game.ServerStorage.ScreenGui:Clone().Parent = player.PlayerGui
        end
    end
end)
0
This is what I used a short while after mraznboy's reply and some experimenting. Scaii_0 145 — 6y

Answer this question