Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why the .Touched stops working after a while?

Context resumee:

  • I made an AnimationEvent guided skill that creates followed lightnings that fall in the mouse position.
  • These cloned lightnings has scripts that uses .Touched:Connect() to damage players.
  • The lightning spawned also creates a 3thrd spherical part that is the explosion in the ground before it vanishes.
  • These cloned explosions (spherical Parts that grows and fades out) has scripts that uses .Touched:Connect() to damage players.

Problem:

The Touched event in the explosions and in the lightning stops working after a while. The more I move my character or the mouse the sooner it stops working, or sometimes after the skill hits my own char.

Also, the skill has no script that makes it not to damage the player casting, but somehow it started behaving like this in some point of the development, I don't know if with this i'm facing a bug or if it is just some normal behavior of animation called events (wouldn't want it different though).

  • Local Script with the Player
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character
if not character then
	character = game.Players.LocalPlayer.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
-- storm:
local StormCast = game.ReplicatedStorage.StormCast
local StormCastTrack = humanoid:LoadAnimation(StormCast)
local cooldown = false

UIS.InputBegan:Connect(function(tecla) 
	if tecla.KeyCode == Enum.KeyCode.E then 

		if not cooldown then
			cooldown = true
			StormCastTrack:Play()
		else
			print("Raios em cooldown.")
		end
		
		connection1 = StormCastTrack:GetMarkerReachedSignal("BeforeEnd"):Connect(function()
			StormCastTrack.TimePosition = 1.05
		end)
		
		connection2 = StormCastTrack:GetMarkerReachedSignal("SkyBlast"):Connect(function()
			RemoteEvent:FireServer("SkyBlast")
			local SkyBlast = game.ReplicatedStorage.SkyBlast
			local SkyBlast_C = SkyBlast:Clone()
			SkyBlast_C.Parent = game.Workspace
			SkyBlast_C.Position = Vector3.new(0,33,0)+ character.LowerTorso.Position
			local function fadeout()		
				while SkyBlast_C.Transparency < 0.95 do
					SkyBlast_C.Transparency = SkyBlast_C.Transparency + 0.1
					wait(0.01)
				end
				SkyBlast_C:Destroy()
			end
			fadeout()
		end)
		
		connection3 = StormCastTrack:GetMarkerReachedSignal("StartCasting"):Connect(function()
			while StormCastTrack.IsPlaying do
				RemoteEvent:FireServer("StormCast", mouse.hit)
				local r = math.random(0,150)/100
				wait(r)
			end
		end)
		
		UIS.InputEnded:Connect(function(tecla) 
			if tecla.KeyCode == Enum.KeyCode.E then 
				connection1:disconnect()
				connection2:disconnect()
				connection3:disconnect()
				StormCastTrack:Stop()
				delay(2, function() if cooldown == true then cooldown = false end end)
			end
		end)
	end
end)
  • Server Script:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local StormCast = game.ReplicatedStorage.StormCast

	
RemoteEvent.OnServerEvent:Connect(function(player, request, dado)
	
	if request == "SkyBlast" then
		local character = player.Character
		local SkyBlast = game.ReplicatedStorage.SkyBlast
		local SkyBlast_CS = SkyBlast:Clone()
		SkyBlast_CS.Name = "SkyBlast_CS"
		SkyBlast_CS.Parent = game.Workspace
		SkyBlast_CS.Position = Vector3.new(0,33,0)+ character.LowerTorso.Position
	end
	
	local StormCast = game.ReplicatedStorage.StormCast
	if request == "StormCast" then
		local raio1 = game.ServerStorage.Raio1
		local Raio1 = raio1:Clone()
		Raio1.Parent = workspace
		Raio1.Position = Vector3.new(dado.X,dado.Y + 29,dado.Z) + Vector3.new(math.random(-30,30)/10,0,math.random(-30,30)/10)
		Raio1.Orientation = Raio1.Orientation + Vector3.new(0, math.random(-175,175), 0)
	end
	
	
end)
  • part of Server Script inside the Lightning (.touched damage and calls explosion):
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true
		hit.Parent.Humanoid:TakeDamage(5)
		delay(0.3, function(bounce)debounce = false end)
		
	end
end)

spawn(function(explodir)
	local boomC = boom:Clone()
	boomC.Parent = workspace
	boomC.Position = raio.Position - Vector3.new(0,29,0)
end)
  • part of the Server Script inside the explosion (.touched damage)
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true
		hit.Parent.Humanoid:TakeDamage(5)
		delay(0.5, function(bounce)debounce = false end)
	end
end)

1 comment

0

Nice answer layout.

1 answer

Explosions are not base parts and they can't fire a touch event if you touch them.

4 comments

0

These what i call "explosions" are not the Instances called explosion, they are spherical parts that grows and fades out.

0

Maybe it has to do with the debounce. Try changing those.

0

It isn't. I've checked if the event was firing before the code checks if debounce is true.

0

Regardless, explosions have an event called '.Hit'.

This discussion is preserved as it was. New answers, comments, and votes are closed.