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

Attempt to perform arithmetic (divide) on number and table? Number thinks it's a table?

Asked by
Zeuxulaz 148
4 years ago
Edited 4 years ago

There are 3 IntValues and they represent an H, S or V value (as in hue, saturation and value). Hue's value is in a number range of 0 to 359 and saturation and value's are in a number range on 0 to 255.

I have a LocalScript inside a Framecalled "Color":

-- Variables
local Hue = script.Parent.Parent.H
local Saturation = script.Parent.Parent.S
local Value = script.Parent.Parent.V
local Color = nil
local ColorHSV = script.Parent.Parent.ColorHSV
local H = nil
local S = nil
local V = nil
local GetHSV = require(script.Parent.Parent.GetHSV)

-- Set color
while wait() do

    -- Get colors
    local HSV = GetHSV:GetHSV(script.Parent.Parent.H.Value, script.Parent.Parent.S.Value, script.Parent.Parent.V.Value)

    -- Set colors
    ColorHSV.Value = HSV
    script.Parent.BackgroundColor3 = ColorHSV.Value

end

In line 10 of the local script it is getting a ModuleScript here:

local module = {}

module.GetHSV = function(Hue, Saturation, Value)

    local H = 0
    local S = 0
    local V = 0
    local N = 0

    if Hue ~= 0 then
        N = 359 / Hue
    end

    if Hue ~= 0 then
        H = 1 / N
    elseif Hue == 0 then
        H = 0
    end

    if Saturation ~= 0 then
        N = 255 / Saturation
    end

    if Saturation ~= 0 then
        S = 1 / N
    elseif Saturation == 0 then
        S = 0
    end

    if Value ~= 0 then
        N = 255 / Value
    end

    if Value ~= 0 then
        V = 1 / N
    elseif Value == 0 then
        V = 0
    end

    return Color3.fromHSV(H, S, V)

end

return module

If you've worked with HSV before, you would know that in:

Color3.fromHSV(H, S, V)

H, S and V have to be in a number range of 0 to 1 like:

Color3.new(R, G, B)

Unlike:

Color3.fromRGB(R, G, B)

Which has to be from 0 to 255.

What the module does is it converts the 3 H, S and V IntValues into:

Color3.fromHSV(H, S, V)

The problem is that when I call the GetHSV(Hue, Saturation, Value) function from line 11:

N = 359 / Hue

It prints (in the output):

12:06:08.288 - ModuleScript:11: attempt to perform arithmetic (div) on number and table

In the output, by "div" it means divide, in case you didn't know already.

As the output says, Hue is a table, when it is clearly not, as in line 16 of the LocalScript it is being called from, Hue is put as, "script.Parent.Parent.H.Value", and H.Value is an IntValue, not a table.

Help?

1 answer

Log in to vote
1
Answered by
Nootian 184
4 years ago

Solution

So, I checked it out and there was a very small issue with it

Look on line 16, with the colon you get the error, but with a period you do not, but I think it is very strange that with a colon, it thinks the first parameter is a table.

-- Variables
local Hue = script.Parent.Parent.H
local Saturation = script.Parent.Parent.S
local Value = script.Parent.Parent.V
local Color = nil
local ColorHSV = script.Parent.Parent.ColorHSV
local H = nil
local S = nil
local V = nil
local GetHSV = require(script.Parent.Parent.GetHSV)

-- Set color
while wait() do

    -- Get colors
    local HSV = GetHSV.GetHSV(script.Parent.Parent.H.Value, script.Parent.Parent.S.Value, script.Parent.Parent.V.Value)

    -- Set colors
    ColorHSV.Value = HSV
    script.Parent.BackgroundColor3 = ColorHSV.Value

end
0
hmmm thats strange Zeuxulaz 148 — 4y
Ad

Answer this question