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

How do you search for children using string values?

I have this bit of code, i'm trying to find the child of a part with the same name as a string value. How do I fix this?

local gui = LocalPlayer.PlayerGui:FindFirstChild('UI2')
	local ArmorName = gui.Frame.Armors.EquipScript.armorname.Value
local armors = game.ServerStorage.Armors:GetChildren()
			
	for i = 1, #armors do
  		if armors[i].Name == ArmorName then
		--do stuff
		end

4 comments

0

is this a server script or local script

0

if it's a local script,you cant access the ServerStorage

0

if it's a server script, you can't access a localplayer

0

It's a server script in server storage, and don't worry, the localplayer is called from a remote event so that definitely is not a problem.

2 answers

I got a similiar code from someone when I asked a question here at Scripting Helpers and now I just changed it so it fits for your needs. Hope this helps!

for i, v in pairs(armors) do
    if v.Name == ArmorName then
	    --do stuff
    end
end

1 comment

0

This is good but it really depends on its use. If you just want to find the armor name and make it do stuff you don't have to write a table for this.

I'm merely repeating the comments but anyways. Localscripts are scripts that are meant for the client/user. Serverscripts are, you guessed it, meant for the server. Both scripts have access limitations in them, for example, LocalPlayer does not exist in a serverscript while ServerStorage contents are inaccessible in a localscript.

A simple counter to your situation is to use remotes.

A localscript will gather information from the GUI and pass it as an argument to a remote stored in ReplicatedStorage.

The remote will have two parameters, the client who invoked the remote (automatically provided; "client") and the name of the armor ("ArmorName").

Run this when it is invoked:

ArmorModel = game.ServerStorage.Armors:FindFirstChild(ArmorName)
-- Do Stuff

2 comments

1

If there is only 1 armor with that name then just do game.ServerStorage.Armors[ArmorName]

0

Whoops, I'll fix that.

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