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

IsA is not a valid member of Color3?

Asked by 5 years ago

ServerScript

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Colours = ReplicatedStorage.Colours
local Factory = ServerStorage.CloneSmith.FactoryNotes
local Generator = require(Factory)

local ModelClass = Instance.new("Model")
ModelClass.Parent = game.Workspace

local NewPart = Instance.new("Part")
NewPart.Parent = ModelClass
-- Create new Model and add a Part inside it


Generator.ColourNotes(ModelClass,Color3.fromHSV(1,1,1))
-- Invoke function from Module

ModuleScript

local module = {}

--[ Variables ]--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

--[ Functions ]--

-- Note Colourer, input: Model/Instance, Colour3.Value/Value
function module.ColourNotes(model,colour)
    if model:IsA("Model") then -- Errors here, IsA is not a valid member of Color3
        local PartsDecendants = model:GetChildren()

        for i,v in ipairs(PartsDecendants) do
            v.Color = colour
        end
    end
end

I am copy and pasting the code from the ServerScript to the command bar but it errors, somehow the model I am passing to :IsA() is a color...

2 answers

Log in to vote
1
Answered by
nilVector 812 Moderation Voter
5 years ago
Edited 5 years ago

If you create a function for a table with . rather than :, the first parameter of the function is to be the object itself.

When using :, self is implicitly passed through the function.

local module = {}

function module:ColourNotes(model, colour)
    print(module == self) --> true
end

return module

When using ., the table itself must be the first parameter of the function.

local module = {}

function module.ColourNotes(self, model, colour)

end

return module

module:ColourNotes(...) is equivalent to module.ColourNotes(module, ...). We use the self keyword, because it is convenient and easy to understand. However, it may be called whatever you want. In your case, you are calling your first parameter model, when it's not really the model. What you can do to fix this is simply change the function definition to use : instead and call the function with : as well OR keep the . and change the parameters of your function to be self, model, colour.

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

After copying your code into roblox studio putting the server script in workspace, and naming the module script "FactoryNotes", adding a ColorValue named Colour to ReplicatedStorage and putting it in a folder called "CloneSmith" the folder being parented by ServerStorage I found that the code worked perfectly (Assuming that the code was supposed to make a red brick in the workspace) after I added return module to the end of the ModuleScript, maybe try that?

Module Script

local module = {}

--[ Variables ]--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

--[ Functions ]--

-- Note Colourer, input: Model/Instance, Colour3.Value/Value
function module.ColourNotes(model,colour)
    if model:IsA("Model") then -- Errors here, IsA is not a valid member of Color3
        local PartsDecendants = model:GetChildren()

        for i,v in ipairs(PartsDecendants) do
            v.Color = colour
        end
    end
end

return module --Only thing I had to add before it worked flawlessly

Answer this question