✓ Accepted answer
It seems you have not understood the principles of Remote Events and its usage in Roblox Games
What is Filtering Enabled?
Filtering Enabled is a property of Workspace that determines if changes from the Client should be replicated to the Server or not. Think of it as a Boundary that separates two different country.
Now, to get into the other country, you will need a Passport. And that Passport is what we call Remote Events and Functions
What are Remote Events and Remote Functions?
Remote Events and Functions are Roblox Instances that allows communication between Server Script and Client Script. By communication, it means that it allows one script to listen to the other scripts instructions.
##Procedure
- Make sure
FilteringEnabled is checked on, It can be found by clicking on Workspace and going over its Properties in Properties menu.
- Start by hovering over
Replicated Storage and insert a Remote Event.
- Name the
Remote Event to your desire.
- Insert a
Local Script in StarterPlayerScripts and a Server Script in Workspace
Server Sided Script
- Begin by declaring variables that you might possible use.
- Create a new
function that detects when a Part is Touched.
- Connecting the
function to Touched Event.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
local Part = workspace.Part;
local function On_Part_Touched (x)
print("What touched me?" .. x.Name);
if x.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(x.Parent);
RemoteEvent:FireClient(Player);
end;
end;
Part.Touched:Connect(On_Part_Touched);
Client Sided Script
- Begin by declaring the same variables you declared before.
- Create a new
function that detects when Remote Event is fired.
- Connect the event using
OnClientEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
local function On_Client_Event ()
print("I was Invoked");
end;
RemoteEvent.OnClientEvent:Connect(On_Client_Event);
Description
So what exactly did we do in both scripts. Lets begin with Server Script.
Server Script:
- Created a
function that fires RemoteEvent using FireClient function.
- Will only
FireClient when Humanoid is found. Thus will not fire when Part is not touched by Humanoid Part.
FireClient() requires Player argument because we need to have an identity. A Passport without an identity cannot be a passport.
Now lets see on Local Script
Local Script:
- Created a
function that is invoked when RemoteEvent has been fired.
- If it has been fired, it will print
I was invoked,
- if it has not been fired, then it won't print anything.
Now let's apply this concept on your actual script.
Server Sided Script.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
local Part = workspace.Part;
local function On_Part_Touched (x)
print("What touched me?" .. x.Name);
if x.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(x.Parent);
RemoteEvent:FireClient(Player);
end;
end;
Part.Touched:Connect(On_Part_Touched);
Client Sided Script.
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");
local ScreenGui = PlayerGui:WaitForChild("ui");
local Button = ScreenGui.TextButton;
local Frame = ScreenGui.Frame;
local function On_Client_Event ()
print("Invoked");
Frame.Visible = true;
end;
local function On_Button_Clicked ()
script.Parent.Parent.Frame.Visible = true;
end;
RemoteEvent.OnClientEvent:Connect(On_Client_Event);
Button.MouseButton1Down:Connect(On_Button_Clicked);
Have a lovely day of coding.
3 comments
Player gui is invisible to the server, thus you shouldn't use a server script to change it (also explains why it works on studio since it is client only bar local server)
also use :Connect :connect is deprecated
Can you post a answer tho?