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

How do you turn this script into a module script?

Asked by
Zerio920 285 Moderation Voter
9 years ago
function fire(a,b)
local last=a;
local size=((a-b).magnitude)/50;
while((b-last).magnitude>size)do
local p=script.p:Clone();
p.Parent = game.Workspace.lightning;
p.formFactor=3;
p.Size=Vector3.new(.25,.25,size);
p.Anchored=true;
p.CanCollide=false;
p.Transparency=0;
p.Name='wt';
local x=math.rad(math.random(-15,15))*-5;
local y=math.rad(math.random(-7.5,7.5))*-2.5;
local z=math.rad(math.random(-10,10))*-1.5;
p.CFrame=CFrame.new(last,b)*CFrame.Angles(x*0.5 + y,y*1.25,z)*CFrame.new(0,0,-(size/2.5));
p.BrickColor=BrickColor.new(1);
local pp=script.PointLight:Clone();
pp.Parent = p
last=(p.CFrame*CFrame.new(0,0,-(size/2))).p;
end;
end;

while script.Parent ~= nil do
fire(game.Workspace.F1.Rod.Wire.Position,game.Workspace.F2.Rod.Wire.Position)
wait()
for i,v in ipairs (game.Workspace.lightning:GetChildren()) do
if v:IsA("BasePart") then
    v:Destroy()
end
end
end

I'd want to turn this into a module script so I could just use the "fire(a,b)" function without having to repaste the code every time.

2 answers

Log in to vote
1
Answered by 9 years ago

In a module script just return what you want to use in other scripts.

So inside of a module script:

function fire(a,b)
local last=a;
local size=((a-b).magnitude)/50;
while((b-last).magnitude>size)do
local p=script.p:Clone();
p.Parent = game.Workspace.lightning;
p.formFactor=3;
p.Size=Vector3.new(.25,.25,size);
p.Anchored=true;
p.CanCollide=false;
p.Transparency=0;
p.Name='wt';
local x=math.rad(math.random(-15,15))*-5;
local y=math.rad(math.random(-7.5,7.5))*-2.5;
local z=math.rad(math.random(-10,10))*-1.5;
p.CFrame=CFrame.new(last,b)*CFrame.Angles(x*0.5 + y,y*1.25,z)*CFrame.new(0,0,-(size/2.5));
p.BrickColor=BrickColor.new(1);
local pp=script.PointLight:Clone();
pp.Parent = p
last=(p.CFrame*CFrame.new(0,0,-(size/2))).p;
end;
end;

while script.Parent ~= nil do
fire(game.Workspace.F1.Rod.Wire.Position,game.Workspace.F2.Rod.Wire.Position)
wait()
for i,v in ipairs (game.Workspace.lightning:GetChildren()) do
if v:IsA("BasePart") then
    v:Destroy()
end
end
end

return fire

Then inside the other script

local fire = require(game.ServerScriptStorage.WhateverYouNamedIt)
fire(x,y)
Ad
Log in to vote
-2
Answered by 9 years ago

copy and paste it into a module script?

0
I know there's something that goes at the beginning and end though for it to function, since Modulescripts need to be activated with "require". Zerio920 285 — 9y
0
require(module script name) Harrison_Ford 5 — 8y

Answer this question