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