I'm trying to make a lightning ability sort of thing. As of now, I'm working on the first move, in which the user will create a ball of lightning and throw it at the mouse's position. Right now it seems to work just fine, but the damage never works. I made a function and tried to trigger the function whenever the parts are touched, but it doesn't trigger anything. I've tried other ways of doing this as well, like using the default

boom1.Touched:Connect(function(hit)

	-- Stuff here

end

but it still doesn't do anything. I've tested with prints, and I believe the issue is simple in the Touched event. Am I doing it wrong? It's worked just fine with other abilities before this.

Server Script:

-- Replicated Storage
local repStorage = game:GetService("ReplicatedStorage")
local powers = repStorage:WaitForChild("Powers")
local lightningEvents = powers:WaitForChild("Lightning")

local rEvent = lightningEvents:WaitForChild("R")
local tEvent = lightningEvents:WaitForChild("T")
local vEvent = lightningEvents:WaitForChild("V")

local function tagged(hit,player)
	local isThere = false
	
	for i,v in pairs(hit.Parent:GetChildren()) do
		if v.Name == "Creator" then
			isThere = true
		end
	end
	
	if not isThere then
		local tag = Instance.new("StringValue",hit.Parent)
		tag.Name = "Creator"
		tag.Value = player.Name
	else
		local tag = hit.Parent.Creator
		tag.Value = player.Name
	end
end

-- Events
rEvent.OnServerEvent:Connect(function(player,enabled,mouseCFrame)
	
	-- Player Stuff
	local char = player.Character
	local rightHand = char:WaitForChild("RightHand")
	
	-- Stats
	local stats = player.Stats
	local power = stats.Power
	
	local powerLvl = power.PowerLevel
	
	-- Lightning Ball
	if enabled == false then
		
		lightningBall = script:WaitForChild("Lightning Ball"):Clone()
		
		-- Setting Positions
		lightningBall.CFrame = rightHand.CFrame
		lightningBall.Parent = char
		
		-- Welding
		weld = Instance.new("Weld",rightHand)
		weld.Part0 = rightHand
		weld.Part1 = lightningBall
		
	elseif enabled == true then
		
		weld:Destroy()
		lightningBall.Anchored = true
		
		local tweenService = game.TweenService
		
		local tweenInfo = TweenInfo.new(
			1,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.In,
			0,
			false
		)
		local partProperties = {
			Position = mouseCFrame.p
		}
		
		local tween = tweenService:Create(lightningBall,tweenInfo,partProperties)
		tween:Play()
		
		wait(1)
		
		-- Meshes
		local boom1 = script:WaitForChild("Boom1"):Clone()
		local boom2 = script:WaitForChild("Boom2"):Clone()
		
		-- Setting Positions
		boom1.CFrame = CFrame.new(lightningBall.CFrame.X,lightningBall.CFrame.Y,lightningBall.CFrame.Z) * CFrame.Angles(math.random(-360,360),math.random(-360,360),math.random(-360,360))
		boom2.CFrame = CFrame.new(lightningBall.CFrame.X,lightningBall.CFrame.Y,lightningBall.CFrame.Z) * CFrame.Angles(math.random(-360,360),math.random(-360,360),math.random(-360,360))
		
		lightningBall:Destroy()
		
		boom1.Parent = game.Workspace
		boom2.Parent = game.Workspace
		
		-- Growing Explosion
		for i = 1,100,5 do
			
			boom1.Size = Vector3.new(i,i,i)
			boom2.Size = Vector3.new(i,i,i)
			
			boom1.Transparency = i/100
			boom2.Transparency = i/100
			
			wait()
			
		end
		
		-- Damage
		local db = false
		local function damage(hit)
			
			tagged(hit,player)
			
			if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name and not db then
				
				db = true
				local humanoid = hit.Parent.Humanoid
				
				humanoid:TakeDamage((powerLvl.Value*0.75)*math.random(5,15))
				db = false
				
			end
			
		end
		
		boom1.Touched:Connect(damage)
		boom2.Touched:Connect(damage)
		
		boom1:Destroy()
		boom2:Destroy()
		
	end
	
	
end)

Local Script:

-- Player Stuff
local player = game.Players.LocalPlayer
local char = player.Character

local humanoid = char:WaitForChild("Humanoid")
local rootPart = char:WaitForChild("HumanoidRootPart")

-- Input
local UIS = game:GetService("UserInputService")
local mouse = player:GetMouse()

-- Replicated Storage
local repStorage = game:GetService("ReplicatedStorage")
local powers = repStorage:WaitForChild("Powers")
local lightningEvents = powers:WaitForChild("Lightning")

local rEvent = lightningEvents:WaitForChild("R")
local tEvent = lightningEvents:WaitForChild("T")
local vEvent = lightningEvents:WaitForChild("V")

-- Stats
local stats = player:WaitForChild("Stats")
local powerStat = stats:WaitForChild("Power")

local power = powerStat:WaitForChild("PowerLevel")

-- Debounces and Cooldowns
local db1 = false
local db2 = false
local db3 = false

local ballCooldown = 10

-- Other
local ballEnabled = false

UIS.InputBegan:Connect(function(input, gameStuff)
	
	if gameStuff then return end
	
	if input.KeyCode == Enum.KeyCode.R and db1 == false then
		
		if ballEnabled == true then
			
			db1 = true
			rEvent:FireServer(ballEnabled,mouse.Hit)
			wait(ballCooldown)
			ballEnabled = false
			
		elseif ballEnabled == false then
			
			rEvent:FireServer(ballEnabled,nil)
			ballEnabled = true
			
		end
		
		db1 = false
		
	elseif input.KeyCode == Enum.KeyCode.T and db2 == false and power.Value >= 50 then
		
		db2 = true
		
		tEvent:FireServer()
		
		db2 = false
		
	elseif input.KeyCode == Enum.KeyCode.V and db3 == false and power.Value >= 100 then
		
		db3 = true
		
		vEvent:FireServer()
		
		db3 = false
		
	end
	
end)

4 comments

0

In the first script you seem to connect the Touched event to the boom parts then immediately :Destroy() it. There isn't a yield in between to make way for something to actually touch it.

0

The event has time to get triggered while the explosions are growing. I've also tried putting the function and event before the growing, but that did the same thing, nothing.

0

Well I thought I did, but I just tried that, and it's working now. :/

0

Thanks for the help though!