✓ Accepted answer
Hey ViciousViperV2,
I will guide you as to how I would go about doing this with FilteringEnabled on. First, I would put a RemoteEvent in Replicated Storage and then put the LocalScript under the Button that the player will need to click in order for the hat to be selected. Then, when the player selects a hat, I would activate that RemoteEvent's OnServerEvent, which the ServerScript should be listening for and then the ServerScript is what would clone the hat into the Character. That's the basis of what I would do. I will show you a personal example of the 2 events in-use and link you to a wiki page that can help you perhaps understand them better. Here is the wiki page for RemoteEvents being used and below is the code that will show a RemoteEvent in-use.
##MouseButton1Down Event in the LocalScript to fire the RemoteEvent:
local button = script.Parent
local rs = game:GetService("ReplicatedStorage")
button.MouseButton1Down:Connect(function()
local event = rs:WaitForChild("RemoteEvent")
event:FireServer()
end)
##OnServerEvent in the ServerScript to make all the cloning happen:
local rs = game:GetService("ReplicatedStorage")
local hat = rs:WaitForChild("Hat")
local event = rs:WaitForChild("RemoteEvent")
event.OnServerEvent:Connect(function(plr)
local char = workspace[plr.Name]
local new_hat = hat:Clone()
new_hat.Parent = char
end)
##By the way, I chose to parent the Remote Event and Hat to ReplicatedStorage because, in FilteringEnabled, ReplicatedStorage is available to both the Client and the Server.
#Well, I hope I helped out in one way or another. Below are all the links.
Anonymous Functions
Remote Events API Page
:GetService() Method
:WaitForChild() Method
MouseButton1Down Event
OnServerEvent
:FireServer() Method
~~ KingLoneCat
3 comments
Wow, thanks for the quick and detailed response. However, here is my issue. I have 100's of assets in ReplicatedStorage, and using i,v in pairs to get all of the items, and generate the button. When that button is pressed, I need to send the item as like an object, to then find in RepStorage and clone. How would I do that?
I would find the name of the item that the button is pressed for. I don't know how your game is made so I'm not sure how you would get the name of the item that is selected from the customization system but, when you do that, use for _,v in next, ReplicatedStorage:GetChildren() do and then, check if v is equal to the object that is selected's name. You can send the name of the object as an argumen
As an argument, like this: :FireServer([name of the object]) and then to receive that, all you have to do is in the function that receives it add another parameter for the argument so, like this: event.OnServerEvent:Connect(function(player, name) for _,v in next, rs:GetChildren() do if v.Name == name then [CODE] end end end)