I have a function that runs when a condition is met inside of another function. Here is my code:
local bullet = game.ReplicatedStorage.testbullet
local head = script.Parent:FindFirstChild("Head")
local ReplicatedStorage = script.Parent
local event = Instance.new("RemoteEvent", ReplicatedStorage)
event.Name = "bullet"
local debounce = false
local sound = Instance.new("Sound")
sound.Parent = head
sound.SoundId = "rbxassetid://392838370"
sound.Volume = 2
sound.Playing = false
local sound2 = Instance.new("Sound")
local function Hurt(Part)
if debounce == false then
if Part.Parent:FindFirstChild("Humanoid") then
Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health-25
debounce = true
Part.BrickColor = BrickColor.new("Really red")
Part.Material = "Neon"
wait(1)
Part:Destroy()
wait(1)
debounce = false
end
end
end
local function shootbullet()
local debounce = false
local Fireball = bullet:Clone()
--local attachment = Instance.new("Attachment")
--attachment.Parent = script.Parent.Parent:FindFirstChild("Left Arm")
--local particles = game.ReplicatedStorage["Cyborg Assets"].particles.Attachment.ParticleEmitter:Clone()
--particles.Parent = attachment
--sound.Playing = true
wait(0.7)
Fireball.BrickColor = BrickColor.new("Institutional white")
Fireball.Transparency = 0
Fireball.TopSurface = 0
Fireball.BottomSurface = 0
Fireball.CanCollide = false
Fireball.CFrame = head.CFrame*CFrame.new(0,0,-10)
Fireball.Parent = game.Workspace
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Parent = Fireball
BodyVelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.velocity = head.CFrame.lookVector*50
Fireball.Touched:connect(Hurt)
--attachment:Destroy()
--particles:Destroy()
wait(10)
Fireball:Destroy()
end
event.OnServerEvent:connect(shootbullet)
Is there a way to send the variable "Fireball" through the "Fireball.Touched:connect(Hurt)" little snippet of code?

5 comments
Also, I suggest you use :Connect instead of :connect() because lower-case is deprecated
and it looks worse
The variable is defined inside of the second function, so it is unreachable inside of the first function. I need the functions to be in this order to allow the projectile to actually do damage properly.
This concept should work. If you define "Value" outside the functions (at the top) and change the value from another function, it should replicate the value to all the other functions as well
I’ll try that.