Can someone please help me with this function, Every time I compile it, it throws *"attempt to index a number value"* for the "Pos" variable, and idk how to fix this, again, can someone please help **ASAP**... (*The function splits a part in two from a midpoint based from the Pos value.*)
function SplitEarth(Pos, OldPrt, Type, Params)
local Base = OldPrt.CFrame.Y - (OldPrt.Size.Y/2)
local Top = OldPrt.CFrame.Y + (OldPrt.Size.Y/2)
if Type == 1 then --[ Horizontal split. ]
--[ Below is my problem, I don't see any indexing here... ]
local PosY1 = Pos + ((Top - Pos).magnitude/2) --[ The first Y value, for the part on top. ]
local PosY2 = Base + ((Base + Pos).magnitude/2) --[ The second Y value. ]
--[[local NewY1 = ().magnitude --[ I'll work on these two later. ]
local NewY2 = ().magnitude
local Prt1 = OldPrt:clone()
Prt1.Size = Vector3.new(OldPrt.Size.X, NewY1, OldPrt.Size.Z)
Prt1.Position = Vector3.new(OldPrt.CFrame.X, PosY1, OldPrt.CFrame.Z)
Prt1.Parent = OldPrt.Parent
local Prt2 = OldPrt:clone()
Prt2.Size = Vector3.new(OldPrt.Size.X, NewY2, OldPrt.Size.Z)
Prt2.Position = Vector3.new(OldPrt.CFrame.X, PosY2, OldPrt.CFrame.Z)
Prt2.Parent = OldPrt.Parent]]
elseif Type == 2 then --[ Vertical split. ]
return
elseif Type == 3 then --[ Diagonal split. ]
return --[ I have an idea how to to this, but I do welcome suggestions... ]
end
end --[ 1 = horiz. split, 2 = vert. split, 3 = diag. split, 4 = chunk split. ]
If you can help, and soon, I will be very grateful; Regards, Xetrax

10 comments
Lol, idk how, but I guess it made my main question a part of the code... whoops, I also just now noticed a spelling error of mine in a comment...
Fixed my spelling error... :|
Why are you putting [ ] around your comments? Also -- can you quote the actual, full error rather than paraphrase? I think you've misunderstood it.
Putting the brackets around my comments is just a style of mine, and I'll add the full error here: 23:16:40.920 - Workspace.FractureTest.Break:31: attempt to index a number value 23:16:40.920 - Stack Begin 23:16:40.921 - Script 'Workspace.FractureTest.Break', Line 31 - global SplitEarth 23:16:40.921 - Script 'Workspace.FractureTest.Break', Line 55 23:16:40.921 - Stack End
If the number value that you are trying to index (read) is 'Pos', and you're getting that error, then 'Pos' is simply not a number. There is no fault in this function, but rather a problem with the arguments that you are supplying to it from elsewhere.
I thought of that, so I changed the name of "Pos", yet it still threw me the same error. and Pos is a number, I have triple checked, the error is thrown when a value is indexed in the way a table or string would be referenced, but Pos is a number value, and this is why the error is confusing me.
Changing the name doesn't affect anything, as long as the same name is used consistently throughout the script. You have triple checked? Find the exact line where the error occurs, note all the index operations that take place (this includes referencing a variable). Now, before that line, use individual print() statements to see what the values are . You will find which values are erroneous.
Thanks, I'll try this shortly, but one last thing, I did that... aaand I even printed the type() of the Pos variable (number) and the result of the formula I'm trying to get to work, the error happens when I try to include Pos in the formula, it just stops dead...
I see now. Top and Pos are numbers, but not vectors. You're trying to calculate (Top - Pos).magnitude. I think you meant simply '(Top - Pos)/2'.
Ahhh, Thank you.