this one is pretty hard to explain, but basically, i have a flare gun tool with a script and once the flare is fired, it prints the position it was fired, but from another script; a module script in which the function is called from the flare gun script:
local module = {}
function module.HelicopterCall()
local TweenService = game:GetService("TweenService")
local Panel = workspace.Helicopter:Clone()
Panel.Parent = workspace
local PanelRoot = Panel.PrimaryPart
local Helidestination = workspace.HeliDestination.CFrame
local PanelSlideInfo = TweenInfo.new(20, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime) -- Let's use all defaults here
)
local PanelSlideTween = TweenService:Create(PanelRoot, PanelSlideInfo, {
CFrame = Helidestination
})
PanelSlideTween:Play()
Panel.PrimaryPart["Helicopter idle"]:Play()
end
return module
in the module function, the destination of the tween is a parts CFrame, which is not what im trying to do, in the flare gun script it prints where the flare is shot, how could i get that position its shot in another script (the module)
Hmm. If you want to pass values from Server to the ModuleScript simply make a function that takes an argument.
e.g.
--Server
local Module = require(script.ModuleScript)
local Value = 5
local DoubledValue = Module:DoubleNumber(Value)
print(DoubledValue)--prints 10
--ModuleScript
local Module = {}
function Module:DoubleValue(InValue)
return InValue * 2
end
return Module
Alternatively you can just use bindable events if you want to move data between 2 ServerScripts
how would that work if InValue has nothing to do with Value in the server script? this is the FlareGun script for refrence
--CONFIG--
--CONFIG--
--DO NOT TOUCH--
local FlareGunClone = script.Parent:Clone()
FlareGunClone.Parent = game:GetService("ReplicatedStorage")
local IsReady = true
local Module = require(game.ServerScriptService.FlareGun)
local EnforcementRandom = math.random(1, 3)
local Enforcement1 = workspace.Folder.FlareEnforcement1
local Enforcement2 = workspace.Folder.FlareEnforcement2
local Enforcement3 = workspace.Folder.FlareEnforcement3
local FlareRemote = game:GetService("ReplicatedStorage").FlarePosition
local TweenService = game:GetService("TweenService")
local Character
local Humanoid
local Flare = workspace.Flare
function BodyVelocityFlare()
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(400000, 400000, 400000)
BodyVelocity.P = 10000
BodyVelocity.Velocity = Vector3.new(0, 100, 0)
BodyVelocity.Parent = script.Parent.FlarePart
print(script.Parent.FlarePart.Position)
wait(3)
script.Parent.FlarePart.PointLight.Enabled = true
BodyVelocity:Destroy()
script.Parent.FlarePart.CanCollide = true
wait(15)
script.Parent.FlarePart:Destroy()
end
script.Parent.Equipped:Connect(function()
Character = script.Parent.Parent
Humanoid = Character.Humanoid
--local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Player = game.Players:GetPlayerFromCharacter(Character)
local Backpack = Player.Backpack
local FlareContactUI = Player.PlayerGui.FlareContact
local FlareReloadAnim = Humanoid.Animator:LoadAnimation(script.Parent.FlareReload)
local FlareShootAnim = Humanoid.Animator:LoadAnimation(script.Parent.FlareShoot)
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(FlareContactUI.TextLabel, tweenInfo, {Transparency = 1})
local tweenInfo = TweenInfo.new(
1, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween2 = TweenService:Create(FlareContactUI.TextLabel, tweenInfo, {Transparency = 0})
FlareContactUI.TextLabel.Visible = true
script.Parent.Activated:Connect(function()
if IsReady == true and Backpack:FindFirstChild("Flare") then
IsReady = false
script.Parent.Handle.Load:Play()
FlareReloadAnim:Play()
FlareReloadAnim.Stopped:Connect(function()
FlareShootAnim:Play()
end)
FlareShootAnim.Stopped:Connect(function()
script.Parent.Handle.Fire:Play()
script.Parent.Handle.WeldConstraint1:Destroy()
BodyVelocityFlare()
script.Parent.FlarePart.Parent = workspace
end)
wait(10)
if EnforcementRandom == 1 then
Enforcement1:Play()
FlareContactUI.TextLabel.Text = "All units, close on suspect."
tween2:Play()
wait(10)
tween:Play()
end
if EnforcementRandom == 2 then
Enforcement2:Play()
FlareContactUI.TextLabel.Text = "Contact Confirmed."
tween2:Play()
wait(10)
tween:Play()
end
if EnforcementRandom == 3 then
Enforcement3:Play()
FlareContactUI.TextLabel.Text = "Target compromised, move in-move in."
tween2:Play()
wait(10)
tween:Play()
end
Module.HelicopterCall()
--[[Module.CallDrop(
{
script.Parent,
script.Parent.Handle.Position,
}
)
--]]
IsReady = false
Flare:Destroy()
script.Parent:Destroy()
end
end)
end)
Well in module scripts you can actually pass in your own values as arguments.
Like this
Script
ModuleScript:FunctionName(Value)--Argument
ModuleScript
function ModuleScript:FunctionName(Value)--Parameter
print(Value)
end
When you make ths function in the module script make an argument. It works similar to how you pass values into functions.
local function OnTouch(HitPart)--Parameter is Retrieved
HitPart:Destroy()-- Do stuff to HitPart
end
Part.Touched:Connect(OnTouch)--Argument is automatically passed in
It basically works the same way except it is cross multiple scripts.
In your case you would have to make a parameter for Position and pass the position into the modulescript everytime you call the argument.
Module.HelicopterCall(Vector3.new(0,3,10)) You can pass a value in here
Then
function module.HelicopterCall(Position) --You now can refer to the Vector3.new(0,3,10) in this variable
local TweenService = game:GetService("TweenService") -- You don't need to get the service everytime you call this function btw
local Panel = workspace.Helicopter:Clone()
Panel.Parent = workspace
local PanelRoot = Panel.PrimaryPart
local Helidestination = workspace.HeliDestination.CFrame
local PanelSlideInfo = TweenInfo.new(20, -- Time
Enum.EasingStyle.Quad, -- EasingStyle
Enum.EasingDirection.InOut, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime) -- Let's use all defaults here
)
local PanelSlideTween = TweenService:Create(
PanelRoot,
PanelSlideInfo,
{CFrame = Helidestination}
)
PanelSlideTween:Play()
Panel.PrimaryPart["Helicopter idle"]:Play()
end