Hello! I made a basis for tool’s functions, like equip and unequip. But i think there is something wrong!
No, script working beautiful, but… I think you already know my problem.
So, here you are:
Main local script in Starter pack:
local tools = {"Shovel", "Brick"}
local selection = Instance.new("SelectionBox")
selection.Name = "ToolSelection"
selection.Parent = workspace
selection.LineThickness = 0.2
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local rwait = function()
return game:GetService("RunService").RenderStepped:wait()
end
repeat wait() until game.Loaded
for _, i in pairs(tools) do
local succ, err = pcall(function()
local tool = plr.Backpack:FindFirstChild(i) assert(tool, "Tool is nil.")
local module = script:FindFirstChild(i.."Module") assert(module, "Tool's module is nil.")
local self = require(module)
self.Tool = tool
self.Selection = selection
tool.Equipped:connect(function()
if self.Equipped then self.Equipped(self) end
end)
tool.Unequipped:connect(function()
if self.Unequipped then self.Unequipped(self) end
end)
end)
if not succ then
warn(string.format("%s tool are useless, plz delete it! Error: %s", i, err))
else
warn(i.." tool was loaded!")
end
end
Test model script in main local script named “ShovelModule”:
return {
Equipped = function(self)
print(self, self.Name, self.Tool)
self.Tool = "lol"
-- yes, there is nothing here, only lol and some print for test.
end
-- someone ate unequip :P
}
Thanks for your help in advance!