Hello, I am trying to make a script that can find the tool in the ReplicatedStorage. And I wanted to use a StringValue with the value of the tool's name, but I don't know how to do it. Can someone help me, please?
This is the script I use:
local WepName = script.StringValue.Value local Weapon = game.ReplicatedStorage:FindFirstChild(WepName)
But the problem is, the Value of the StringValue contains spaces. For example, the Value is called "Imperial Gold Sword". It breaks the FindFirstsChild thing and I don't know what to do. Someone help me, please. (Sorry about my bad English, it's not my first language.)
I don't think the issue is related to the name of the weapon. Here's why.
Recall FindFirstChild()
's two parameters:
FindFirstChild(name, recursive)
Argument 1, which gets assigned to name
, should be a string. Strings are allowed to have whitespaces; variable names are not.
Argument 2, which gets assigned to recursive
, should be a boolean. This parameter determines if the function will search recursively, meaning it will search through descendants instead of just children. By default, this is set to false.
Since this doesn't work...
FindFirstChild("Imperial Gold Sword")
...why not do this instead?
FindFirstChild("Imperial Gold Sword", true)
Note that you have to make sure that the weapon is actually named Imperial Gold Sword
and does not contain any extra, missing, or incorrect characters.
Hello! What I would suggest is using this symbol _
to represent spaces. It's not as pretty, but it does work! So you would set the value to Imperial_Gold_Sword
instead of Imperial Gold Sword
This is the best I can do. I hope this helps you!
Best,
TheLastHabanero