Honestly I’d prefer to use 1 table instead of multiple tables, imagine having 100 tools, despite the fact that you have to create 100 tables, there’s not an actual way to get the reference to them by checking the name of the tool in my opinion.
is that OOP (or OPP lol) cuz i have only month experience in lua scripting… i heard somewhere about using one table (as a formula in math) to make a script MORE general.
i actually think that learning scripting language with real people is more easier when learning it just by tutorials or smth else ig
Well, no, that is not OOP (i forgot what it stands for lol), that’s just a table.
And yeah, in my opinion you should refuse watching most of the long tutorials on the youtube, some of them are useful but most of them are either useless and time-wasting or too confusing.
And yes, it’s alot easier with real people.
Just check the roblox documents, and try to use them in the roblox studio to become experienced with them, looking at other people’s codes is a good way aswell, i started learning from there.
local placePrompt = script.Parent
local Tools = {
["BluePrintBackpack"] = {Cost = 75, Give = "Backpack"},
["BluePrintBarrel"] = {Cost = 175, Give = "Barrel"},
["BluePrintBeneliM4"] = {Cost = 325, Give = "BeneliM4"},
["BluePrintDeagle"] = {Cost = 150, Give = "Deagle"},
["BluePrintKalash"] = {Cost = 200, Give = "Kalash"},
["BluePrintPistol"] = {Cost = 100, Give = "Pistol"},
["BluePrintScrapArmor"] = {Cost = 125, Give = "ScrapArmor"},
["BluePrintShootgun"] = {Cost = 275, Give = "Shootgun"},
["BluePrintAntiHero"] = {Cost = 1200, Give = "AntiHero"},
}
placePrompt.Triggered:Connect(function(player)
local character = player.Character
if not character then
warn("У игрока нет Character")
return
end
local heldTool = character:FindFirstChildOfClass("Tool")
if not heldTool then
for _, obj in pairs(character:GetChildren()) do
if obj:IsA("Tool") then
heldTool = obj
break
end
end
end
if not heldTool then
print(player.Name .. "you not holding item")
return
end
local data = Tools[heldTool.Name]
if not data then
print(heldTool.Name .. "u can't use for craft this item")
return
end
print(player.Name .. " Holding " .. heldTool.Name)
print("Scrap need: " .. data.Cost)
print("What u get: " .. data.Give)
-- later write logic for items
end)
i rewrited script and its working, thanks all for diligence
The reason this script works while the other one didn’t is because, in the other one, the ToolName field of your table wasn’t the actual names of the tool
From your new script, I can see that you are using the index of the tools table, instead of (what you renamed) give, showing me that the names of the tools were the indexes, rather than CraftCostModule.ToolName
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.