Why the .Touched stops working after a while?
Asked by
5 years ago Edited 5 years ago
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
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local Players = game:GetService( "Players" ) |
03 | local player = Players.LocalPlayer |
04 | local character = player.Character |
06 | character = game.Players.LocalPlayer.CharacterAdded:Wait() |
08 | local humanoid = character:WaitForChild( "Humanoid" ) |
09 | local mouse = player:GetMouse() |
10 | local RemoteEvent = game.ReplicatedStorage.RemoteEvent |
12 | local StormCast = game.ReplicatedStorage.StormCast |
13 | local StormCastTrack = humanoid:LoadAnimation(StormCast) |
16 | UIS.InputBegan:Connect( function (tecla) |
17 | if tecla.KeyCode = = Enum.KeyCode.E then |
23 | print ( "Raios em cooldown." ) |
26 | connection 1 = StormCastTrack:GetMarkerReachedSignal( "BeforeEnd" ):Connect( function () |
27 | StormCastTrack.TimePosition = 1.05 |
30 | connection 2 = StormCastTrack:GetMarkerReachedSignal( "SkyBlast" ):Connect( function () |
31 | RemoteEvent:FireServer( "SkyBlast" ) |
32 | local SkyBlast = game.ReplicatedStorage.SkyBlast |
33 | local SkyBlast_C = SkyBlast:Clone() |
34 | SkyBlast_C.Parent = game.Workspace |
35 | SkyBlast_C.Position = Vector 3. new( 0 , 33 , 0 )+ character.LowerTorso.Position |
36 | local function fadeout() |
37 | while SkyBlast_C.Transparency < 0.95 do |
38 | SkyBlast_C.Transparency = SkyBlast_C.Transparency + 0.1 |
46 | connection 3 = StormCastTrack:GetMarkerReachedSignal( "StartCasting" ):Connect( function () |
47 | while StormCastTrack.IsPlaying do |
48 | RemoteEvent:FireServer( "StormCast" , mouse.hit) |
49 | local r = math.random( 0 , 150 )/ 100 |
54 | UIS.InputEnded:Connect( function (tecla) |
55 | if tecla.KeyCode = = Enum.KeyCode.E then |
56 | connection 1 :disconnect() |
57 | connection 2 :disconnect() |
58 | connection 3 :disconnect() |
60 | delay( 2 , function () if cooldown = = true then cooldown = false end end ) |
01 | local RemoteEvent = game.ReplicatedStorage.RemoteEvent |
02 | local StormCast = game.ReplicatedStorage.StormCast |
05 | RemoteEvent.OnServerEvent:Connect( function (player, request, dado) |
07 | if request = = "SkyBlast" then |
08 | local character = player.Character |
09 | local SkyBlast = game.ReplicatedStorage.SkyBlast |
10 | local SkyBlast_CS = SkyBlast:Clone() |
11 | SkyBlast_CS.Name = "SkyBlast_CS" |
12 | SkyBlast_CS.Parent = game.Workspace |
13 | SkyBlast_CS.Position = Vector 3. new( 0 , 33 , 0 )+ character.LowerTorso.Position |
16 | local StormCast = game.ReplicatedStorage.StormCast |
17 | if request = = "StormCast" then |
18 | local raio 1 = game.ServerStorage.Raio 1 |
19 | local Raio 1 = raio 1 :Clone() |
20 | Raio 1. Parent = workspace |
21 | Raio 1. Position = Vector 3. new(dado.X,dado.Y + 29 ,dado.Z) + Vector 3. new(math.random(- 30 , 30 )/ 10 , 0 ,math.random(- 30 , 30 )/ 10 ) |
22 | Raio 1. Orientation = Raio 1. Orientation + Vector 3. new( 0 , math.random(- 175 , 175 ), 0 ) |
- part of Server Script inside the Lightning (.touched damage and calls explosion):
01 | script.Parent.Touched:Connect( function (hit) |
02 | if hit.Parent:FindFirstChild( "Humanoid" ) and debounce = = false then |
04 | hit.Parent.Humanoid:TakeDamage( 5 ) |
05 | delay( 0.3 , function (bounce)debounce = false end ) |
10 | spawn( function (explodir) |
11 | local boomC = boom:Clone() |
12 | boomC.Parent = workspace |
13 | boomC.Position = raio.Position - Vector 3. new( 0 , 29 , 0 ) |
- part of the Server Script inside the explosion (.touched damage)
1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) and debounce = = false then |
4 | hit.Parent.Humanoid:TakeDamage( 5 ) |
5 | delay( 0.5 , function (bounce)debounce = false end ) |