Help with tool check system

help

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local CraftCostModule = {
	["BluePrintScrapArmor"] = {ScrapCost = 125, ToolName = "ScrapArmor"},
	["BluePrintShootgun"] = {ScrapCost = 175, ToolName = "Shootgun"},
	["BluePrintBackpack"] = {ScrapCost = 100, ToolName = "Backpack"},
	["BluePrintPistol"] = {ScrapCost = 85, ToolName = "Pistol"},
	["BluePrintKalash"] = {ScrapCost = 195, ToolName = "Kalash"},
	["BluePrintDeagle"] = {ScrapCost = 125, ToolName = "Deagle"},
	["BluePrintBeneliM4"] = {ScrapCost = 225, ToolName = "BeneliM4"},
	["BluePrintBarrel"] = {ScrapCost = 175, ToolName = "Barrel"},
	["Anti-Hero M9"] = {ScrapCost = 1000, ToolName = "AntiHeroM9"},
}
local craftModel = script.Parent.Parent.Parent
local proxyPart = craftModel:WaitForChild("ProxyPart")
local placePrompt = proxyPart:WaitForChild("PlaceBluePrint")
local payPrompt = proxyPart:WaitForChild("PayScrap")
local actionText = payPrompt.ActionText
local payEvent = ReplicatedStorage:WaitForChild("PayScrapEvent")

placePrompt.Triggered:Connect(function(player)
	local character = player.Character
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		warn("Humanoid not finded")
		return
	end

	local heldTool = nil
	local matchedItemName = nil

	for itemName, data in pairs(CraftCostModule) do
		local tool = character:FindFirstChild(data.ToolName)
		if tool and tool:IsA("Tool") then
			heldTool = tool
			matchedItemName = itemName
			break
		end

		if not heldTool then
			local equippedTool = humanoid:FindFirstChildOfClass("Tool")
			if equippedTool and equippedTool.Name == data.ToolName then
				heldTool = equippedTool
				matchedItemName = itemName
				break
			end
		end
	end

	if not heldTool then
		warn("U dont have tool um")
		return
	end
end)

i wanted do tool check (" i mean craft system and output saying i dont have tool many times i can’t solve it")

1 Like

instead of

try for itemName, tool in pairs(CraftCostModule) do

and remove local tool = character:FindFirstChild(data.ToolName)
not guaranted itll help but just try!

попробуй)

not working

не работает((((((

script again saying character don’t have tool

local heldTool = nil
local matchedItemName = nil

for itemName, data in pairs(CraftCostModule) do
    local toolInCharacter = character:FindFirstChild(data.ToolName)
    local equippedTool = humanoid:FindFirstChildOfClass("Tool")
    
    if toolInCharacter and toolInCharacter:IsA("Tool") then
        heldTool = toolInCharacter
        matchedItemName = itemName
        break
    elseif equippedTool and equippedTool.Name == data.ToolName then
        heldTool = equippedTool
        matchedItemName = itemName
        break
    end
end

if not heldTool then
    warn("U don't have tool")
    return
end

Крч у тебя не работало из за того что ты во первых использовал break что мешало скрипту во втором ты во время цикла используешь if not held tool а это НЕ ПРАВИЛЬНО должно быть ПОСЛЕ цикла (просто заглушает работу) если не сработает то сорян я все попробовал (

Правильный вариант если че (просто скопи пасти)

I don’t see why it wouldn’t work, other than data.ToolName not being set correctly to the name of the tools?

The second check in your if statement it useless

I would suggest you add a print(Character:FindFirstChildWhichIsA(“Tool”)) (outside the loop), to check if it prints the tool or nil

Tools aren’t under the humanoid unless his game is done very weird lol

i tried don’t worked, soo i right now trying do without module script for Less hassle and rewriting the script completely.

Did it print nil?

Char limit jsjdjdjfjjfbfjfjf

i starter scripter I only started learning Lua well a month ago.

What you mean about character limit?, i thinking maybe do local + server script and remote for CHARACTER

To post a reply on the forum, it needs to be at least thirty characters long, which is very annoying

If you do print(Character:FindFirstChildWhichIsA(“Tool”)), it will print the tool’s name, if it found a tool, or it’ll print nil, if it didn’t find a tool

By doing this print, and looking at what it prints in the console (or output) it helps to figure out what the issue is. If it prints the tool name, then you probably entered the names of the tools wrong. If it prints nil, then idk how that could be

local CraftCostModule = {
	["BluePrintScrapArmor"] = {ScrapCost = 125, ToolName = "ScrapArmor"},
	["BluePrintShootgun"] = {ScrapCost = 175, ToolName = "Shootgun"},
	["BluePrintBackpack"] = {ScrapCost = 100, ToolName = "Backpack"},
	["BluePrintPistol"] = {ScrapCost = 85, ToolName = "Pistol"},
	["BluePrintKalash"] = {ScrapCost = 195, ToolName = "Kalash"},
	["BluePrintDeagle"] = {ScrapCost = 125, ToolName = "Deagle"},
	["BluePrintBeneliM4"] = {ScrapCost = 225, ToolName = "BeneliM4"},
	["BluePrintBarrel"] = {ScrapCost = 175, ToolName = "Barrel"},
	["Anti-Hero M9"] = {ScrapCost = 1000, ToolName = "AntiHeroM9"},
}

return CraftCostModule

Try translating my message with google translate, I don’t think you understood it

I think the name of the tool is written incorrectly

I know the problem Yooooooo
Lets go

According to the image you should use ItemName instead of data.ToolName

From this screenshot, you have a tool named “BluePrintScrapArmor”. However, when you iterate through CraftCostModule, you’re checking if the user has a entirely different named tool, which they do not, so heldTool never gets defined:

-- Say, for example, we had BluePrintScrapArmor in our inventory.
	for itemName, data in pairs(CraftCostModule) do
		local tool = character:FindFirstChild(data.ToolName) -- data.Toolname would be "ScrapArmor", which the user does not have.
		if tool and tool:IsA("Tool") then -- Since 'tool' does not exist, this condition is false
			heldTool = tool
			matchedItemName = itemName
			break
		end -- heldTool never gets defined: heldTool is nil

		if not heldTool then 
			local equippedTool = humanoid:FindFirstChildOfClass("Tool") -- By default, the character model is the parent of the tool, not the humanoid
			if equippedTool and equippedTool.Name == data.ToolName then -- This condition is also false
				heldTool = equippedTool
				matchedItemName = itemName
				break
			end -- heldTool does not get defined again: heldTool is still nil
		end
	end

I assume you want to check if the user has the blueprint and enough scraps before they are able to craft the tool. You can achieve this by just checking if a Tool instance exists inside of the character model and, if it does, retrieve the value from the dictionary:

placePrompt.Triggered:Connect(function(player)
	local character = player.Character
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		warn("Humanoid not finded")
		return
	end
        
    local heldTool = character:FindFirstChildOfClass("Tool")
    if heldTool and CraftCostModule[heldTool.Name] then
        -- the rest of your code
        -- you can get scraps needed and toolname like so:
        local scrapsNeeded = CraftCostModule[heldTool.Name].ScrapCost
        local craftedTool = CraftCostModule[heldTool.name].ToolName
    end
end)
			

oh wait.. youre actaully right. But i dont understand why people create such a hard tables (as for me), and it might be better if he did it like

Tool1 = {
   Name = "Tool"
   Cost = 3 -- idk lol
}
``