OnClientEvent stops working after death

Hello, developers! :wave:

I have been making a game about throwing boxes into people, however, recently I’ve been making a flash bang perk that blinds people around the box with an explosion using an RemoteEvent. :camera_flash::sparkles:

Though after testing I found out that, if you die, the remote event stops working, i have gotten NO errors, NOTHING, the remote event stops printing completely, while the script that sends the remote event seems to work fine. :cry::pray:

I cannot find people talking about this, so I’ve come here for help! :woman_superhero:

Script that sends remote event:

	if plrHRP.particleAttach.flash_symbol.Enabled == true then
		local exp_flash = Instance.new("Explosion")
		exp_flash.Visible = false
		exp_flash.Parent = workspace
		exp_flash.Position = Obj.Position
		exp_flash.BlastPressure = 0
		exp_flash.BlastRadius = 10
		Obj.Particles.flash_fx:Emit(1)
		Obj.flash_sfx:Play()
		exp_flash.Hit:Connect(function(hit)
			local flash_dbc = false
			if flash_dbc == false then
			flash_dbc = true
			local playerService = game:GetService("Players")
			if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
				exp_flash:Destroy()
			local playerFromCharacter = playerService:GetPlayerFromCharacter(hit.Parent)
			print(playerFromCharacter)
				hit.Parent.flash_perk.flash_hit:FireClient(playerFromCharacter)
					print(hit.Parent.flash_perk.flash_hit:FireClient(playerFromCharacter))
			end
			task.wait(0.1)
			flash_dbc = false
			end
		end)

Script that receives the remote event:

local plr = game.Players.LocalPlayer

local dbc = false

plr.Character.flash_perk.flash_hit.OnClientEvent:Connect(function()
	print("flashy")
	if dbc == false then
	script.Parent.flash_hit_Sound:Play()
	game.Lighting.flash_bang_fx.Enabled = true
	game.Lighting.flash_bang_fx.Brightness = 1
	dbc = true
	for i = 0, 20 do
		game.Lighting.flash_bang_fx.Brightness -= 0.05
		task.wait(0.1)
	end
	game.Lighting.flash_bang_fx.Enabled = false
	end
	task.wait(0.5)
	dbc = false
end)

I know my script is trash, I’m kinda bad ngl. :skull:

1 Like

Can you confirm the script where the event is recieved still exists upon respawn?

Reconnect the function everytime the player respawns, or place the code inside StarterCharacterScripts

1 Like

It does. This stuff confusing as hell.

try adding the script in StarterCharacterScripts so it resets each time the player die

i had the same problem before and fixed it by chaning the script to Starter Character

Neither of this stuff makes a difference. the character is not being cached, so it’s always getting the latest character.

Yeah, just added it to StarterCharacterScripts before u said that, still doesn’t work…

The script runs once and gets the first spawned character, after they respawn the code still uses the old character variable

maybe add the event as a variable and wait for it
local event = plr.Character:waitForChild(flash_perk.flash_hit)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.