Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would you make fire server return table values?

Asked by 5 years ago
Edited 5 years ago

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?

0
what do u want to do with the values? there's nothing wrong with this code, other than your `if true then`, which is completely pointless Gey4Jesus69 2705 — 5y
0
This is every confusing, print Tool.Name, followed by “Value it pulls” isn’t specific enough Ziffixture 6913 — 5y
0
its also `:IsA()`, not `:isA()` Gey4Jesus69 2705 — 5y
0
What I'm trying to do is turn every tool from startergear into a GUI button. Like an inventory. But you can't mess with the GUI from the server and the client can't mess with "StarterGear" SimpleFlame 255 — 5y
View all comments (4 more)
0
Edited the code to clear up what I'm trying to make happen SimpleFlame 255 — 5y
0
Why do you need startergear. The children in that folder should be inside of the backpack already. xPolarium 1388 — 5y
0
Use a RemoteFunction instead: table.insert(sometable, tool) return sometable. Also, xPolariums point.  Azarth 3141 — 5y
0
Okay and where would the remote function go? SimpleFlame 255 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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 UIListLayouts 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!


Accept and upvote if this helps!

0
Yes thank you. I sometimes have a hard time getting my point across this is exactly what I'm talking about only I want it to loop through startergear and not the backpack. SimpleFlame 255 — 5y
0
no problem, i changed line 6 for you. upvote and accept if this helped Gey4Jesus69 2705 — 5y
0
Running into the same problem here. Error on line 6 "StarterGear" doesn't exist for the client since this is being run from a GUI. SimpleFlame 255 — 5y
0
oh sorry, i forgot roblox didnt show that to the client. let me rewrite this Gey4Jesus69 2705 — 5y
View all comments (5 more)
0
updated Gey4Jesus69 2705 — 5y
0
note you'll have to manually put them in StarterGear, because the StarterPack clones its items into the backpack, not startergear Gey4Jesus69 2705 — 5y
0
Yeah this is what I wanted. It's going in and getting the children in startergear. I made it print Remote:InvokeServer() and it just returns a table value so I did print(Remote:InvokeServer().Name) and that returns nil? SimpleFlame 255 — 5y
0
Yeah still giving me nil values for everything SimpleFlame 255 — 5y
0
the tools variable returns a table (because GetChildren() returns a table). thats why i looped through it in the local script Gey4Jesus69 2705 — 5y
Ad

Answer this question