Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

FindFirstChild cannot find a part in workspace which is referred by a variable?

Asked by 5 years ago
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.Button1Down:Connect(function()
    local par = Instance.new("Part",workspace)
    if workspace:FindFirstChild(par) then
        print("ie")
    else
        print("nope")
    end
end)

This prints "nope" everytime. But if I switch it to findfirstchild("Part") then it works.

IS there a fix for this?

0
FindFirstChild accepts a string argument and returns a part object. You're giving it the part object it's meant to return? fredfishy 833 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.Button1Down:Connect(function()
    local par = Instance.new("Part",workspace)
    if workspace:FindFirstChild(par.Name) then
        print("ie")
    else
        print("nope")
    end
end)

As someone else (@fredfishy) mentioned the FindFirstChild functions receives a string as an input and outputs the first object with the name of the input, however you input the object instead.

Keep in mind that this piece of code will find the first part that comes with that name, so i'm guessing that you're trying to stop it from doing something if there's already a part.

Ad

Answer this question