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

Why is this way I'm using to script this not work? (I think its :FindFirstChild())

I'm making a sort of admin gui, and for some reason most of the commands are not working, the reason they're not working is because most of them use the same way to find something, which I'm pretty sure is why it's not working, but I don't know why its not working, but I do know that if this way gets fixed/someone tells me why it's not working, I'll have the rest of them fixed.

Variables not stated in code snippet:

Gui15 = a Textbutton

Holder = A model that holds stringvalues with a players name (Yes, I've checked; It has the players name.

If you can't see all of line 5 for some reason (I can't), the code for it is this:

Instance.new("ForceField",game:GetService("Players")[v.Value]:FindFirstChild("Character"))

I use :FindFirstChild and :GetService() because of possible renaming of objects, I also believe :FindFirstChild is the cause of it not working, not too sure.

Gui15.MouseButton1Down:connect(function()
    for _,v in pairs(Holder:GetChildren()) do
        if v:IsA("StringValue") then
            if game:GetService("Players")[v.Value]:FindFirstChild("Character") then
                Instance.new("ForceField",game:GetService("Players")[v.Value]:FindFirstChild("Character"))
            end --It's not showing the end of the line above with the sites code block for some reason (For me at least)

        end
    end
end)


1 answer

✓ Accepted answer

Hi!

You are unable to use WaitForChild() or FindFirstChild() on Character because it is not a child of player, but instead a property.

Just turn ":FindFirstChild("Character")" into ".Character" on lines 4 and 5. Don't worry, the character won't be renamed, because again it is a property and not a child. You cannot rename properties.

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