In my game, I have multiple characters which have different parts for their arms/hands. For example, one is a treasure chest that has a lock with hands. Another doesn't have hands to hold an item with, so it uses its teeth. So, a potential solution for holding items was to adapt items by giving them a welding script.
However, the elseif/else if statements are being ignored, and the script only accounts for the very first if statement. The only output error is that if the character does not have the first statement's part, it will not be a valid member of the model. The script works fine for the first statement's character, however.
Here is a snippet of the script, for some context:
script.Parent.AncestryChanged:connect(function() local Char= script.Parent.Parent local weld = Instance.new("Weld") if Char.ArmR ~= nil then weld.Parent = Char.ArmR weld.Part0 = Char.ArmR weld.Part1 = script.Parent.Handle elseif Char.Bar ~= nil then weld.Parent = Char.Bar weld.Part0 = Char.Bar weld.Part1 = script.Parent.Handle elseif Char.LegFR ~= nil then weld.Parent = Char.LegFR weld.Part0 = Char.LegFR weld.Part1 = script.Parent.Handle
The script is basically supposed to be saying "If the parent of this tool changes, check the character for "ArmR", and if it doesn't, check if it has "Bar", and so on... Once the arm is found, the weld is formed.". But instead, it seems to say "If the parent of this tool changes, check the character for ArmR."
I have looked at a few tutorials about using Else/Elseif statements, and they seem to be structured this way, so I am confused. Extra context: It is stored in a regular script, as a child of the Tool. The tool is stored within StarterPack, so it is immediately moved to the Backpack.
The .
is used for properties, or a descendant of an instance. By using it, you're telling the script you already know the descendant exists. Instead, use FindFirstChild which will return true if the object is found, and false if it isn't. You'd use it on lines 5,9,and 13 instead of using the .
(can't remember the technical name for the '.' in programming)