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":

01-- Variables
02local Hue = script.Parent.Parent.H
03local Saturation = script.Parent.Parent.S
04local Value = script.Parent.Parent.V
05local Color = nil
06local ColorHSV = script.Parent.Parent.ColorHSV
07local H = nil
08local S = nil
09local V = nil
10local GetHSV = require(script.Parent.Parent.GetHSV)
11 
12-- Set color
13while wait() do
14 
15    -- Get colors
View all 22 lines...

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

01local module = {}
02 
03module.GetHSV = function(Hue, Saturation, Value)
04 
05    local H = 0
06    local S = 0
07    local V = 0
08    local N = 0
09 
10    if Hue ~= 0 then
11        N = 359 / Hue
12    end
13 
14    if Hue ~= 0 then
15        H = 1 / N
View all 44 lines...

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.

01-- Variables
02local Hue = script.Parent.Parent.H
03local Saturation = script.Parent.Parent.S
04local Value = script.Parent.Parent.V
05local Color = nil
06local ColorHSV = script.Parent.Parent.ColorHSV
07local H = nil
08local S = nil
09local V = nil
10local GetHSV = require(script.Parent.Parent.GetHSV)
11 
12-- Set color
13while wait() do
14 
15    -- Get colors
View all 22 lines...
0
hmmm thats strange Zeuxulaz 148 — 4y
Ad

Answer this question