how do i return a variable inside a function that is inside an if statement in a module script and get the returned variable
like this
local module = {
a = function()
local Go
Go = true --this is an example
if Go == true then
return Go --Grab this variable from another script
end
end
}
return module
local module = {
a = function(Number)
if (Number > 20) then
return "Number is bigger than 20"
else
return "Number is smaller than 20"
end
end
}
return module
You need to assign GO as a param in the getGo() function, and then assign it to a variable using local whateverVariableName = getGo(The bool value go here)
local module = {
FindEnemy = function(TowerHumanoid,TowerTorso,Range,Type)
local Occupied = false
local EnemyHumanoid
local EnemyHMR
for i,v in pairs(game.Workspace.Rigs.Zombies:GetChildren()) do
EnemyHumanoid = v:FindFirstChild("Humanoid")
EnemyHMR = v:FindFirstChild("HumanoidRootPart")
if EnemyHumanoid then
if Type == "Auto" and (TowerTorso.Position - EnemyHMR.Position).magnitude <= Range then
print("FoundEnemy")
if not Occupied then
Occupied = true
EnemyHMR.DescendantRemoving:Connect(function()
Occupied = false
end)
else
break
end
elseif Type == "SemiAuto" and (TowerTorso.Position - EnemyHMR.Position).magnitude <= Range then
print("FoundEnemy")
end
elseif (TowerTorso.Position - EnemyHMR.Position).magnitude > Range then
Occupied = false
end
end
if Occupied then
print("Returning")
return Occupied, EnemyHumanoid, EnemyHMR
end
end
}
return module
other script
while wait() do
pcall(function()
local Occupied, EnemyHumanoid, EnemyHMR = FindTarget.FindEnemy()
FindTarget.FindEnemy(TowerHumanoid,TowerTorso,Range,"Auto")
print(FindTarget.FindEnemy())
if EnemyHumanoid then
PlasmaRay.Transparency = 0.1
Dist = (TowerTorso.Position - EnemyHMR.Position).magnitude
PlasmaRay.CFrame = CFrame.new(script.Parent:WaitForChild("PlasmaGun"):WaitForChild("Spinner"):WaitForChild("Start").WorldPosition,EnemyHMR.Position)*CFrame.new(0,0,-Dist/2)
PlasmaRay.Size = Vector3.new(0.1,0.1,Dist)
TowerHMR.CFrame = CFrame.lookAt(TowerHMR.Position,Vector3.new(EnemyHMR.Position.X,TowerHMR.Position.Y,EnemyHMR.Position.Z)) * CFrame.Angles(0,0,0)
PlayStance:Stop()
PlayAttack:Play()
EnemyHumanoid:TakeDamage(20)
script.Parent:WaitForChild("DamageDealt").Value += 1
game.ServerStorage.GiveMoney:Fire(1)
script.Parent:WaitForChild("PlasmaGun"):WaitForChild("PlasmaBall").Transparency = 0.8
elseif Occupied == false then
PlasmaRay.Transparency = 1
script.Parent:WaitForChild("PlasmaGun"):WaitForChild("PlasmaBall").Transparency = 1
PlayAttack:Stop()
PlayStance:Play()
end
TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Top"):WaitForChild("TotalDamage").Text = "DMG: "..script.Parent:WaitForChild("DamageDealt").Value
TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Top"):WaitForChild("TowerName").Text = script.Parent:WaitForChild("TowerName").Value
TowerTorso:WaitForChild("Info"):WaitForChild("Frame"):WaitForChild("Bottom"):WaitForChild("Owner").Text = script.Parent:WaitForChild("Owner").Value
end)
end