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
thanks for the help