I can get the names of all the tools in starter gear but how would I actually use those values?
Script that would be in a GUI
local repStorage = game:GetService("ReplicatedStorage") local remotesFolder = repStorage:WaitForChild("GameRemotes") local inventoryFolder = remotesFolder:WaitForChild("Inventory") local findToolRemote = inventoryFolder:WaitForChild("GetToolEvent") --// Store everything it gets from this into a table findToolRemote:FireServer()
Script in server script service
local repStorage = game:GetService("ReplicatedStorage") local remotesFolder = repStorage:WaitForChild("GameRemotes") local inventoryFolder = remotesFolder:WaitForChild("Inventory") local findToolRemote = inventoryFolder:WaitForChild("GetToolEvent") findToolRemote.OnServerEvent:Connect(function(plr) local startergear = plr:WaitForChild("StarterGear") local backpack = plr:WaitForChild("Backpack") for i,tool in pairs(startergear:GetChildren()) do if tool:IsA("Tool") then --// Add tool to a table the client can use end end end)
How would I use the values the server script gets?
I get what you're talking about, and I do it quite a lot, whether it's to make a custom backpack system or a shop. Here's my setup. In that picture, the Sample
label's Visible
property is set to false. The script loops through the player's backpack and, with each iteration, makes a new text label. Note that UIListLayout
s ignore invisible objects, so the Sample
object will not affect the order.
To accomplish this, we have to use a RemoteFunction
, because the StarterGear
is not visible to the client. Here's the code I used:
--Local Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteFunction") local Players = game:GetService("Players") local player = Players.LocalPlayer player.CharacterAdded:Connect(function(char) wait(1) local tools = Remote:InvokeServer() for _,v in pairs(tools) do local newslot = script.Parent.Sample:Clone() newslot.Text = v.Name newslot.Name = "Slot" .. v.Name newslot.Visible = true newslot.Parent = script.Parent end end)
--Server Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = Instance.new("RemoteFunction") Remote.Parent = ReplicatedStorage function Remote.OnServerInvoke(player) return player.StarterGear:GetChildren() end
The result is this. Hopefully this helps you out. If you have any questions, put them in the comments!