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

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

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?

1 comment

0

FindFirstChild accepts a string argument and returns a part object. You're giving it the part object it's meant to return?

1 answer

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.

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