Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you make fire server return table values?

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?

8 comments

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

0

This is every confusing, print Tool.Name, followed by “Value it pulls” isn’t specific enough

0

its also :IsA(), not :isA()

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"

0

Edited the code to clear up what I'm trying to make happen

0

Why do you need startergear. The children in that folder should be inside of the backpack already.

0

Use a RemoteFunction instead: table.insert(sometable, tool) return sometable. Also, xPolariums point. 

0

Okay and where would the remote function go?

1 answer

✓ Accepted answer

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!

9 comments

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.

0

no problem, i changed line 6 for you. upvote and accept if this helped

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.

0

oh sorry, i forgot roblox didnt show that to the client. let me rewrite this

0

updated

0

note you'll have to manually put them in StarterGear, because the StarterPack clones its items into the backpack, not startergear

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?

0

Yeah still giving me nil values for everything

0

the tools variable returns a table (because GetChildren() returns a table). thats why i looped through it in the local script

This discussion is preserved as it was. New answers, comments, and votes are closed.