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

Script Wont Work in Filtering Enabled?

Asked by 7 years ago
Edited 7 years ago

okay before you refer me to the wiki (LOL), I have been though the wiki front and backk but still cannot get it right. They show how to make certain scripts FE compatible but not the way im trying to do it.

So basically I have it so that when you step on a brick a screen gui pops up. Here is the script I have (BTW it works with FE off);

Script inserted in Brick


local Part = script.Parent Part.Touched:connect(function (HIT) local H = HIT.Parent:FindFirstChild ("Humanoid") if H then Player = game.Players: GetPlayerFromCharacter(HIT.Parent) Player.PlayerGui.ScreenGui.Box.Visible = true end end)

Please help me out with this, it is driving me crazy. Also I know I have to make a local script and a sever script along with a remote event but I just cannot figure out where to place what.

Also I have tried this but it doesnt work

LocalScript

local open = game.Workspace["Floor Brick"]

open.Touched:connect(function()
    open.Script.Open:FireServer()
end)

Server Script

local Part = script.Parent
Part.Touched.OnServerEvent:connect(function (HIT)
    local H = HIT.Parent:FindFirstChild ("Humanoid")
    if H then
        Player = game.Players: GetPlayerFromCharacter(HIT.Parent)
        Player.PlayerGui.ScreenGui.Box.Visible = true


    end

end)
0
Just make the normal on hit script and stuff, but then after (if H then) you would want to fire the server script (everything below (if H then)) Nikkulaos 229 — 7y

4 answers

Log in to vote
0
Answered by
Mineloxer 187
7 years ago
Edited 7 years ago

The problem is that the children of the PlayerGui does not replicate from the client to the server. So you're trying to access ScreenGui from the server, which I assume returns nil.

The simplest way I can think of doing this is creating a RemoteEvent inside of the client and placing it in a folder that replicates to the server. Like, the Backpack of the player. Name it "PopGui" without the quotations. You can name it anything, but keep it simple for now.

Now it is easy, just insert a server script in the part. On touch events for the referenced part, make it fire that remote event.

Server Script

local part = script.Parent

part.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
        --We got the player
        local backpack = player:FindFirstChild("Backpack")
        if backpack then
            --We got the backpack
            local popEvent = backpack:FindFirstChild("PopGui")
            if popEvent then
                --We got the event, now just fire it.
                popEvent:FireClient(player)
            end
        end
    end
end)

The LocalScript will be responsible for enabling the Gui.

LocalScript

--Just some variables to make code readable
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local backpack = player:WaitForChild("Backpack")
local popGuiEvent = backpack:WaitForChild("PopGui")
local screenGui = playerGui:WaitForChild("ScreenGui")

--Handle
popGuiEvent.OnClientEvent:Connect(function()
    screenGui.Box.Visible = true
end)

Some important notes: A good practice is to have a folder with all the remote events. I did not do so in my example for simplicity. But usually you would have a folder containing all the remote events/functions in one place so it is neater. And script(s) that handles each one separately.

Another note, if you would like to check what is replicated to the server/client and what isn't. You can go into the Test tab > Test. But make sure to have the number of player set to at least 1. Now you can open the explorer in the Server Window, and in the client's window and look at the things that has been replicated etc.

I did all of this on the go, so please tell me if you have any questions or errors that I can help you with. Correction is appreciated by anyone.

Ad
Log in to vote
0
Answered by
Troidit 253 Moderation Voter
7 years ago

The solution is actually quite easy.

In Filtering Enabled, server scripts can't affect the settings of player guis. So how do we solve this?

If you turn the script from a Server Script to a local script, it should work just fine. Local Scripts can still detect touch.

LOCAL SCRIPT

local Part = script.Parent
Part.Touched:Connect(function (HIT)
    local H = HIT.Parent:FindFirstChild ("Humanoid")
    if H then
        Player = game.Players: GetPlayerFromCharacter(HIT.Parent)
        Player.PlayerGui.ScreenGui.Box.Visible = true
    end
end)
Log in to vote
0
Answered by 7 years ago

I found the problem in the server script instantly. Part.Touched is an event for the part, but you are defining Touched event as a RemoteEvent. To fix this, do the following;

SERVER SCRIPT

local part = game.Workspace["Floor Brick"] --gets the part

part.Script.Open.OnServerEvent:Connect(function(player,HIT) --you mistaken Open as Touched in your script
    local h = HIT.Parent:FindFirstChild("Humanoid")
    if h then
        local player = game.Players:GetPlayerFromCharacter(HIT.Parent)
        player.PlayerGui.ScreenGui.Box.Visible = true
    end
end)

LOCAL SCRIPT

local open = game.Workspace["Floor Brick"]

open.Touched:Connect(function(HIT) --will make HIT variable on what touched the part
    open.Script.Open:FireServer(HIT) --will pass HIT argument to the RemoveEvent
end)

It will take some time until you understand what is going on. I am not a good explainer but I do know some Filtering Enabled functions and other medium scripting levels. Hope this helped, and good luck with your game :)!

0
Ok so it worked in studio but is not working in roblox. No Gui is popping up CrazyRoblots 13 — 7y
0
Hmm, I would suggest to first join the game (not Studios) and press F9. If you see a Fn button near your Windows key or near your space bar, hold Fn + F9 to view the Developer Console. The Developer Console is like Output in Studios, but on the ROBLOX game. Once you opened, try to find the problem and try to fix it. If you can't show me the error. CounterBoy123 53 — 7y
Log in to vote
-2
Answered by 7 years ago

if it doesnt work in filtering enabled then just turn of filtering enabled

1
Made my day, easiest solution lol. Mineloxer 187 — 7y

Answer this question