I've been spending the past few hours learning about FilteringEnabled, and how I can use it in my shop script. In my script I want a robloxian mannequin in workspace to send information to my GUI, so I have set up a RemoteEvent in that mannequin. Please tell me why this isn't working.
Output: "Unable to cast value to Object"
local ShirtID = (string.sub(script.Parent.Parent.Body.Shirt.ShirtTemplate, 14)) script.Parent.ClickDetector.MouseClick:connect(function() script.Parent:WaitForChild("RemoteEvent"):FireClient(ShirtID) end)
It looks like you are trying to send your variable where you should be referencing a player,
local ShirtID = (string.sub(script.Parent.Parent.Body.Shirt.ShirtTemplate, 14)) script.Parent.ClickDetector.MouseClick:connect(function(player) script.Parent:WaitForChild("RemoteEvent"):FireClient(player, ShirtID) end)
Also this might help you some more.
A simple example of how Filtering Enabled works is as follows:
In the case of doing a Client > Server connection you are obligated to use a remote event or function.
The difference between these two?
Remote Events:
They don't yield the script and wait for a response when they're called just like a normal event.
Remote Functions:
They basically do the same, but with the difference of returning the results of the action done by it. So it callbacks, it needs to return something, it waits , expects to return information.
Having Remotes clarified in a simple way, the next question appears .... Where do I store them? Most of the people actually use ServerScriptService or ReplicatedStorage. Take care that both containers have their differences and it is important to remark them.
ServerScriptService:
This container can only be seen by the server, the client cannot see anything inside of this container.
ReplicatedStorage:
This container can be seen by both server & client as it replicates to both of them.
Going back to the Client > Server connection and having both important components, where to hold it and how to establish the connection we have now clear on what we can use, which in this case is:
Remote Events:
:FireServer() method.
on the LocalScript.
.OnServerEvent()
event to actually establish the connection between Server & Client through the remote.LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage") local exampleEvent = ReplicatedStorage:WaitForChild("exampleEvent") exampleEvent:FireServer("PrintThis")
ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage") local exampleEvent = Instance.new("RemoteEvent", ReplicatedStorage) exampleEvent.Name = "exampleEvent" exampleEvent.OnServerEvent:Connect(function(player, key) if key == "PrintThis" then print("The example Event listened & printed this from the server"); end end)
You might be a bit confused, bare with me.
The LocalScript sends information to the server through the :FireServer() method
. In a Client > Server
connection the first argument sent to the .OnServerEvent() event
is the player, that's why in the moment of the creation of the event in the server script you have "player" as the first argument of the function.
You can send any type of information to the server, remember there is always limitations to what you can send to the server.
Going back to the ServerScript , to establish the connection with the client and be able to get the information sent by the :FireServer() method
we use the .OnServerEvent() event
as previously mentioned. That event will make possible the connection between Client > Server
through a secure way.
As long as you understand this conceptuation you will also be able to understand the inverse, Server > Client
connection and also RemoteFunctions and their different way of nomenclature.
I didn't include the RemoteFunctions & Server > Client because the answer will be too large, I'm leaving you some refference links so you can be a bit autodidact.
Remotes links
Remote example:
http://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events
.OnServerEvent() event:
http://wiki.roblox.com/index.php?title=API:Class/RemoteEvent/OnServerEvent
RemoteFunction:
http://wiki.roblox.com/index.php?title=API:Class/RemoteFunction
Holder links
ServerScriptService:
http://wiki.roblox.com/index.php?title=API:Class/ServerScriptService
ReplicatedStorage:
http://wiki.roblox.com/index.php?title=API:Class/ReplicatedStorage
Hope this helped you , if you have any questions feel free to ask or comment!