local Input = nil
local Obj = {
"FrontRoof",
"Walls"
}
local function OnSelect()
Input = "Remove"
if game.ReplicatedStorage.Input == "Built" then
local RemoveObjects = {
workspace.FrontRoof,
workspace.Walls
}
local mouse = game.Players.LocalPlayer:GetMouse()
local target = mouse.Target
if target == RemoveObjects[1] or RemoveObjects[2] then
local Box = Instance.new("SelectionBox")
Box.Adornee = RemoveObjects[1] or RemoveObjects[2]
Box.Parent = RemoveObjects[1] or RemoveObjects[2]
local function DestroyObject()
mouse.Button1Down:Connect(function()
if mouse.Target:IsA("UnionOperation") or mouse.Target:IsA("Model") or mouse.Target:IsA("Part") and target.Name == Obj[1] or Obj[2] then
target:Destroy()
end
end)
end
end
end
end
local ModuleName = {}
local function Module.OnSelect()
-- code goes here
end
local function Module.DestroyObject()
-- code goes here
end
return ModuleName
You then call functions in the Module by doing
local module = require(pathToModuleScript)
module.OnSelect()
module.DestroyObject()
local ModuleName = {}
local Input = nil
local Obj = {
"FrontRoof",
"Walls"
}
local function OnSelect()
Input = "Remove"
if game.ReplicatedStorage.Input == "Built" then
local RemoveObjects = {
workspace.FrontRoof,
workspace.Walls
}
local mouse = game.Players.LocalPlayer:GetMouse()
local target = mouse.Target
if target == RemoveObjects[1] or RemoveObjects[2] then
local Box = Instance.new("SelectionBox")
Box.Adornee = RemoveObjects[1] or RemoveObjects[2]
Box.Parent = RemoveObjects[1] or RemoveObjects[2]
local function DestroyObject()
mouse.Button1Down:Connect(function()
if mouse.Target:IsA("UnionOperation") or mouse.Target:IsA("Model") or mouse.Target:IsA("Part") and target.Name == Obj[1] or Obj[2] then
target:Destroy()
end
end)
end
end
end
end
return ModuleName
You have to do function ModuleName.OnSelect(). If your functions are not appended to the table that is returned, they cannot be accessed by other scripts.
Again this error pops up
Here’s the module script: local ModuleName = {}
local Input = nil
local Obj = {
"FrontRoof",
"Walls"
}
function ModuleName.OnSelect()
Input = "Remove"
if game.ReplicatedStorage.Input == "Built" then
local RemoveObjects = {
workspace.FrontRoof,
workspace.Walls
}
local mouse = game.Players.LocalPlayer:GetMouse()
local target = mouse.Target
if target == RemoveObjects[1] or RemoveObjects[2] then
local Box = Instance.new("SelectionBox")
Box.Adornee = RemoveObjects[1] or RemoveObjects[2]
Box.Parent = RemoveObjects[1] or RemoveObjects[2]
function ModuleName.DestroyObject()
mouse.Button1Down:Connect(function()
if mouse.Target:IsA("UnionOperation") or mouse.Target:IsA("Model") or mouse.Target:IsA("Part") and target.Name == Obj[1] or Obj[2] then
target:Destroy()
end
end)
end
end
end
end
Here’s the script that calls the module script: local module = require(game:GetService("ReplicatedStorage"):WaitForChild("Destroy"))
local ModuleName = {}
local Input = nil
local Obj = {
"FrontRoof",
"Walls"
}
function ModuleName.OnSelect()
Input = "Remove"
if game.ReplicatedStorage.Input == "Built" then
local RemoveObjects = {
workspace.FrontRoof,
workspace.Walls
}
local mouse = game.Players.LocalPlayer:GetMouse()
local target = mouse.Target
if target == RemoveObjects[1] or RemoveObjects[2] then
local Box = Instance.new("SelectionBox")
Box.Adornee = RemoveObjects[1] or RemoveObjects[2]
Box.Parent = RemoveObjects[1] or RemoveObjects[2]
end
end
end
function ModuleName.DestroyObject()
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target:IsA("UnionOperation") or mouse.Target:IsA("Model") or mouse.Target:IsA("Part") and mouse.Target.Name == Obj[1] or Obj[2] then
mouse.Target:Destroy()
end
end)
end
return ModuleName
local test = require(game:GetService("ReplicatedStorage"):WaitForChild("ModuleScript"))
test.OnSelect()
test.DestroyObject()