hey so, im making a plugin using Bhristt’s Bezier Curve Module
and it ran into an error when i press the plugin button
line 320
plugin script
assert(plugin, "This script must be run as a plugin!")
local toolbar = plugin:CreateToolbar("Bezier Rails")
local pluginButton = toolbar:CreateButton(
"Bezier Curve",
"Create smooth bezier curves",
"http://www.roblox.com/asset/?id=71988552055771")
local module = require(script.Bezier)
--module:Initialise(plugin)
--module:CheckForPluginGlobal()
module.new(workspace.P1, workspace.P2, workspace.P3, workspace.P4)
local points = {}
local lines = {}
local rails = {}
local rail_lenght = 3
local desired_angle = 0
local num_points = 20
local point_folder = script.Folder
function part_creation(size :Vector3, tables, colour :BrickColor, name :string)
local part = Instance.new("Part", point_folder)
part.CanQuery = false
part.Name = name
part.Size = size
part.BrickColor = colour
part.CanCollide = false
part.Anchored = true
table.insert(tables, part)
end
pluginButton.Click:Connect(function()
--local p1 = Instance.new("Part", workspace)
--local p2 = Instance.new("Part", workspace)
--local p3 = Instance.new("Part", workspace)
--local p4 = Instance.new("Part", workspace)
print("yay")
for i = 1, num_points do
part_creation(Vector3.new(.5, .5, .5), points, BrickColor.new("Really red"), "POINT")
end
for i = 1, #points do
local t = (i - 1) / (#points - 1)
-- calculates the position and derivative of the Bezier Curve at t
local position = module:CalculatePositionRelativeToLength(t)
local derivative = module:CalculateDerivativeRelativeToLength(t)
-- sets the position and orientation of the point based on the
-- position and derivative of the Bezier Curve
points[i].CFrame = CFrame.new(position, position + derivative)
end
end)
i made a non-plugin version of what this plugin is trying to do and it works fine
local bezier = require(script.Bezier)
local newbezier = bezier.new(workspace.P1, workspace.P2, workspace.P3, workspace.P4)
local point_folder = Instance.new("Folder", script)
local rail_folder = Instance.new("Folder", script)
local rail_template = script.Rails
local points = {}
local lines = {}
local rails = {}
local rail_lenght = 3
local desired_angle = 0
local num_points = math.floor(newbezier.Length / rail_lenght) + 1
function part_creation(size :Vector3, tables, colour :BrickColor, name :string)
local part = Instance.new("Part", point_folder)
part.CanQuery = false
part.Name = name
part.Size = size
part.BrickColor = colour
part.CanCollide = false
part.Anchored = true
table.insert(tables, part)
end
for i = 1, num_points do
part_creation(Vector3.new(.5, .5, .5), points, BrickColor.new("Really red"), "POINT")
end
for i = 1, num_points - 1 do
local rail_clone = rail_template:Clone()
rail_clone.Parent = rail_folder
table.insert(rails, rail_clone)
end
function update()
local new_num_points = math.floor(newbezier.Length / rail_lenght) + 1
if num_points < new_num_points then
for i = 1, math.abs(new_num_points - num_points) do
part_creation(Vector3.new(.5, .5, .5), points, BrickColor.new("Really red"), "POINT")
end
for i = 1, math.abs(new_num_points - num_points) do
local rail_clone = rail_template:Clone()
rail_clone.Parent = rail_folder
table.insert(rails, rail_clone)
end
elseif num_points > new_num_points then
local removed_point :BasePart = points[#points]
table.remove(points, #points)
removed_point:Destroy()
local removed_rails :Model = rails[#rails]
table.remove(rails, #rails)
removed_rails:Destroy()
end
num_points = new_num_points
end
while task.wait(1) do
local middle = math.floor(num_points/2)
for i = 1, #points do
local t = (i - 1) / (#points - 1)
-- calculates the position and derivative of the Bezier Curve at t
local position = newbezier:CalculatePositionRelativeToLength(t)
local derivative = newbezier:CalculateDerivativeRelativeToLength(t)
-- sets the position and orientation of the point based on the
-- position and derivative of the Bezier Curve
points[i].CFrame = CFrame.new(position, position + derivative)
end
for i = 1, #rails do
local rail :Model= rails[i]
local p1, p2 = points[i].Position, points[i + 1].Position
rail:PivotTo(CFrame.new(0.5 * (p1 + p2), p2)
* CFrame.fromAxisAngle(
Vector3.new(0, 0, 1),
math.rad(
- math.abs(
-1 * math.abs(2*desired_angle/#rails*(i-1-#rails/2)) + desired_angle))))
end
update()
end
i hope im not pushing anything with this