Flashlight script stops working after the player dies

Howdy

goal
the goal of this script is to toggle a flashlight on and off it
issue
it works fine when the player spawns in but after they die the server script seems to stop working,
things i’ve tried
i’ve tried deleting the remote event and everything related after the player died but no luck, i am not getting any errors either.

SERVER SCRIPT

wait(1)
script.Parent =	script.Parent
local man = script.Parent
local bodylight = script.Parent.bodylight
local FLS = false
local on_indi = script.Parent.bodylight.on_indi
local off_indi = script.Parent.bodylight.off_indi
local flashlightclick = bodylight.main.FlashlightClick


 


function lightstate()
	if FLS == false then 
	bodylight.lamp.SpotLight.Brightness = 2
	bodylight.outterlamp.PointLight.Brightness = 0.5
	bodylight.lamp.Material = Enum.Material.Neon 
	bodylight.lamp.Color = Color3.fromRGB (255, 255, 255)
	on_indi.Color = Color3.fromRGB (0, 255, 0)
	off_indi.Color = Color3.fromRGB (0, 0, 0)
	flashlightclick:play()	
	FLS = true
	wait(2)
	elseif FLS == true then 
	bodylight.lamp.SpotLight.Brightness = 0		
	bodylight.outterlamp.PointLight.Brightness = 0	
	bodylight.lamp.Material = Enum.Material.SmoothPlastic 	
	bodylight.lamp.Color = Color3.fromRGB (0, 0, 0)	
	on_indi.Color = Color3.fromRGB (0, 0, 0)
	off_indi.Color = Color3.fromRGB (255, 0, 0)	
	flashlightclick:play()		
	FLS = false
	wait(2)	
	end
end

function wipe()
	print("cleaning up!")
	man.magazine:Destroy()
	man.Union:Destroy()
	man.armor:Destroy()
	man.flashlight_I_O:Destroy()
	script:Destroy()
end

man.flashlight_I_O.OnServerEvent:Connect(lightstate)
man.deathevent.OnServerEvent:Connect(wipe)

LOCAL SCRIPT

wait(1)
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local lightevent = Character.flashlight_I_O
local deathevent = Character.deathevent

function cleanup()
	print("cleaning up!")	
	deathevent:FireServer()
end


UserInputService.InputBegan:Connect(function(Key, IsTyping)
	if Key.KeyCode == Enum.KeyCode.F and IsTyping == false then	
		lightevent:FireServer()
		print("light promted")	
	end
end)

UserInputService.InputBegan:Connect(function(Key, IsTyping)
	if Key.KeyCode == Enum.KeyCode.LeftShift and IsTyping == false then	
		print("sprintin")
	end
end)


Character.Humanoid.Died:connect(cleanup)

player
image

thanks for the help

put the localscript in StarterPlayerScripts

i already did that, server script is in StarterCharacterScripts

if you put a script in StarterCharacterScripts it will run each time the Character Gets Added.

would that break that in this case? it should still be running?

it will reset the whole script basically.

that should be fine then right? it’s just checking if the player hits F and if they do it should fire the server, it’s printing that it’s doing that so i think it’s the server script messing up

1 Like

after Character Dies does the localscript still prints anything?

yup for sure, just tested it is printing fine

that’s okay, cuz then the player respawns and their flashlight should be off by default

can you add a print after if FLS == false then?

regardless no it’s not printing anything if it’s on the server script

can you add a print before the FLS if statement so we can check if the event is really firing?

that’s the issue i don’t think the remote event is firing at all, i did that and it printed nothing

either that or the server stopped listening after the players death

can’t you just change the remote events’s spots to ReplicatedStorage?

is replicated storage for the client only or? that server wide?

no its for both for client and server.

wouldn’t that activate everyones flashlight then?

nope, that won’t effect anyone’s flashlight only the current Player.