Cloning a Hat from the ServerStorage into the Character with Filtering Enabled.
When I click the button, the StringValue's value becomes the name of the frame and then through the Filtering Enabled, I'm trying to read the name of the value located in the client and search it in the ServerStorage and cloning it in the character.
This is the output I'm getting: ServerScriptService.Filtering Enabled:26: attempt to index a nil value
Part of the script in the Client
local hat = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Hat") hat.Value = script.Parent.Parent.Name game.Workspace.FE.Hat:InvokeServer()
In the Server Script
function FE.Hat.OnServerInvoke(player) local Hat = player.PlayerGui.ScreenGui.Hat game.ServerStorage:FindFirstChild(Hat.Value):Clone().Parent = player.Character end
You could try passing the Hat value through the invocation as an argument.
Client:
local hat = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Hat") hat.Value = script.Parent.Parent.Name game.Workspace.FE.Hat:InvokeServer(hat.Value)
Server:
function FE.Hat.OnServerInvoke(player, hat) local Hat = game.ServerStorage:FindFirstChild(hat) if Hat then Hat:Clone().Parent = player.Character end end
I don't know which line is line 26 so I don't know if that was the problem. If not, please elaborate. Hope this helped.
Explanation Edit: On the client, hat.Value is passed to the invocation as whatever the value type is (in this case, a string). The server doesn't even know there's a ValueObject involved-- all it receives is the value.
Let's say hat.Value == "Roblohunk". On line 3 of the LocalScript, before even invoking the server, the script gets the value of hat.Value-- "Roblohunk"-- and then passes it to the server. So, if hat.Value == "Roblohunk", line 3 is basically:
game.Workspace.FE.Hat:InvokeServer("Roblohunk")
This then passes to the OnServerInvoke function which, as you know, automatically takes the player who invoked as a parameter. That means the argument we passed is the second one, which I specified as 'hat'.
Considering the previous example where hat.Value == "Roblohunk", here's an explanation of the function:
function FE.Hat.OnServerInvoke(player, hat) local Hat = game.ServerStorage:FindFirstChild(hat) -- Find the first child named "Roblohunk" (or whatever hat.Value is) in ServerStorage. If a match isn't found, :FindFirstChild() returns nil. So the 'Hat' variable either becomes the hat, or nil. if Hat then -- We check to see if the hat exists (if it found "Roblohunk" in ServerStorage). Hat:Clone().Parent = player.Character -- If it does, we clone it and set its parent to player.Character. end end
Hope this helped to clear it up a bit.