Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to efficiently get a class from other scripts?

Asked by 3 years ago
Edited 3 years ago

I'm making a class where it connects/manipulates tools for the sake of maintaining properly. Once, I invoked the bindable function in the Tool (name is Get). I get this

Output:

  0:40:22.738  attempt to index string with function  -  Client
  20:40:22.738  Stack Begin  -  Studio
  20:40:22.738  Script 'print(workspace.SomePlayer.Tool.Get:Invoke())', Line 1  -  Studio
  20:40:22.738  Stack End  -  Studio

Module:

local module = {}
module.__index = module

function module.new(tool)
    local self = setmetatable({}, module)

    self.Tool = tool
    self.Handle = tool:FindFirstChild("Handle")

    local get = Instance.new("BindableFunction")
    get.Name = "Get"
    get.Parent = self.Tool
    get.OnInvoke = function()
        return self
    end

    return self
end

Command Bar:

print(workspace.SomePlayer.Tool.Get:Invoke())

Rushed edited because I accidentally pressed Ask Question.

Answer this question