How can you use a variable string in FindFirstChild?

I am making a proximity prompt that activates if the player who used it before is holding a tool named L1 through 5 and/or Admin. I’ve tried many different ways and i can’t find out how to implement the variable into :FindFirstChild()

script

local ProximityPromptService = game:GetService("ProximityPromptService")
local ProximityPrompt = script.Parent.ProximityPrompt

local clearance = {
	["L1"] = true,
	["L2"] = true,
	["L3"] = true,
	["L4"] = true,
	["L5"] = true,
	["Admin"] = true,
}

ProximityPrompt.Triggered:Connect(function(playerH)
	local charmod = workspace:FindFirstChild(playerH.Name)
	
	if charmod then
		if charmod:FindFirstChild(clearance, true) then  --issue here
        print("success")
     else
        print("denied")
     end
end

Hello koi1299!

I provided code below that does exactly what you are looking for!

local proximitypromptservice = game:GetService("ProximityPromptService")
local prompt = script.Parent.ProximityPrompt
--
local clearances = {
	"L1",
	"L2",
	"L3",
	"L4",
	"L5",
	"Admin"
}
--
prompt.Triggered:Connect(function(player)
	if player.Character ~= nil then
		local tool = player.Character:FindFirstChildOfClass("Tool")
		if tool then
			if table.find(clearances,tool.Name) then
				print("Allowed!")
			else
				warn("Not allowed!")
			end
		end
	end
end)
1 Like

oh wow, thanks that was unbelievably fast. I’ll be sure to research the contents of the script, much appreciated!