For some reason the touched event for my lightning bolt is only activating when I’m a certain distance away from the target. It doesn’t work up close and I’m not too sure why.
Here is the video:
External MediaHere is the whole entire script:
local Event = game.ReplicatedStorage.LightningBoltEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LightningThrowParticles = ReplicatedStorage.LightningThrowParticles
local BLT = LightningThrowParticles.BackLightningThrow
local BoLT = LightningThrowParticles.BottomLightningThrow
local FLT = LightningThrowParticles.FrontLightningThrow
local LLT = LightningThrowParticles.LeftLightningThrow
local RLT = LightningThrowParticles.RightLightningThrow
local SLT = LightningThrowParticles.SphereLightningThrow
local TLT = LightningThrowParticles.TopLightningThrow
Event.OnServerEvent:Connect(function(Player, MousePosition)
local LightningThrowChargeUp = Player.Character:WaitForChild("RightUpperArm").LightningThrowChargeUp
LightningThrowChargeUp.TimePosition = 2
LightningThrowChargeUp:Play()
local Humanoid = Player.Character:WaitForChild("Humanoid")
Humanoid.WalkSpeed = .1
if Player.PlayerGui:FindFirstChild("StrideLengthAugmenter") then
Player.PlayerGui.StrideLengthAugmenter.IncreaseSpeed.Disabled = true
Player.PlayerGui.StrideLengthAugmenter.DecreaseSpeed.Disabled = true
end
if Player.PlayerGui:FindFirstChild("SpeedGui") then
Player.PlayerGui.SpeedGui.IncreaseSpeed.Disabled = true
Player.PlayerGui.SpeedGui.DecreaseSpeed.Disabled = true
end
local LightningThrowAnimation = Instance.new("Animation")
LightningThrowAnimation.AnimationId = "rbxassetid://12482661484"
local Animator = Humanoid:WaitForChild("Animator")
local LightningThrowAnimationTrack = Animator:LoadAnimation(LightningThrowAnimation)
local LightningTossSound = Player.Character:WaitForChild("RightUpperArm").LightningThrowToss
LightningTossSound.TimePosition = .7
LightningTossSound:Play()
LightningThrowAnimationTrack:Play()
local BLTClone = BLT:Clone()
local BoLTClone = BoLT:Clone()
local FLTClone = FLT:Clone()
local LLTClone = LLT:Clone()
local RLTClone = RLT:Clone()
local SLTClone = SLT:Clone()
local TLTClone = TLT:Clone()
BLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
BoLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
FLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
LLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
RLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
SLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
TLTClone.Parent = Player.Character.Armor.RightLowerArmArmor
BLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
BLTClone.Enabled = true
BoLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
BoLTClone.Enabled = true
FLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
FLTClone.Enabled = true
LLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
LLTClone.Enabled = true
RLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
RLTClone.Enabled = true
SLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
SLTClone.Enabled = true
TLTClone.Color = Player.Character.LeftUpperArm.TrailInner.Color
TLTClone.Enabled = true
task.wait(3.5)
local LightningBolt = game.ReplicatedStorage.LightningPart:Clone()
LightningBolt.Parent = game.Workspace
LightningBolt.CFrame = CFrame.new(Player.Character.HumanoidRootPart.Position, MousePosition)
local VectorForce = LightningBolt.VectorForce
VectorForce.Force = Player.Character.HumanoidRootPart.CFrame.LookVector * 50
local XForce = VectorForce.Force.X
local ZForce = VectorForce.Force.Z
local gravity = game.Workspace.Gravity
local mass = LightningBolt:GetMass()
VectorForce.Force = Vector3.new(XForce, mass * gravity, ZForce)
--LightningBolt.Velocity = CFrame.new(Player.Character.HumanoidRootPart.Position,MousePosition).LookVector * 500
local LightningTraveling = game.ReplicatedStorage.LightningTraveling:Clone()
LightningTraveling.Parent = LightningBolt
LightningTraveling:Play()
local function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") and not hit:IsDescendantOf(Player.Character) then
local BodyVelocity = Instance.new("BodyVelocity", hit.Parent:FindFirstChild("HumanoidRootPart"))
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BodyVelocity.Velocity = Vector3.new(LightningBolt.AssemblyLinearVelocity.X, 10, LightningBolt.AssemblyLinearVelocity.Z)
game.Debris:AddItem(BodyVelocity, 1)
hit.Parent:FindFirstChild("Humanoid").Sit = true
LightningBolt.Explode1.Volume = 5
LightningBolt.Explode1:Play()
LightningBolt.Explode2.Volume = 5
LightningBolt.Explode2:Play()
task.wait(1)
hit.Parent:FindFirstChild("Humanoid").Sit = false
BodyVelocity:Destroy()
end
end
BLTClone.Enabled = false
BoLTClone.Enabled = false
FLTClone.Enabled = false
LLTClone.Enabled = false
RLTClone.Enabled = false
SLTClone.Enabled = false
TLTClone.Enabled = false
Humanoid.WalkSpeed = 12
if Player.PlayerGui:FindFirstChild("StrideLengthAugmenter") then
Player.PlayerGui.StrideLengthAugmenter.IncreaseSpeed.Disabled = true
Player.PlayerGui.StrideLengthAugmenter.DecreaseSpeed.Disabled = true
end
if Player.PlayerGui:FindFirstChild("SpeedGui") then
Player.PlayerGui.SpeedGui.IncreaseSpeed.Disabled = true
Player.PlayerGui.SpeedGui.DecreaseSpeed.Disabled = true
end
task.wait(1)
BLTClone:Destroy()
BoLTClone:Destroy()
FLTClone:Destroy()
LLTClone:Destroy()
RLTClone:Destroy()
SLTClone:Destroy()
TLTClone:Destroy()
LightningBolt.Hitbox.Touched:Connect(onTouched)
game:GetService("Debris"):AddItem(LightningBolt, 20)
end)