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")
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 а это НЕ ПРАВИЛЬНО должно быть ПОСЛЕ цикла (просто заглушает работу) если не сработает то сорян я все попробовал (
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
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)