Hi! I wanna make a flashlight stay with you after you die, but whenever you die it seems to go away.
local player = game.Players.LocalPlayer
local char = player.Character
local cam = workspace.CurrentCamera
local run = game:GetService("RunService")
local PlayerGui = player:WaitForChild("PlayerGui")
local FlashlightGui = PlayerGui:WaitForChild("Flashlight")
local UIS = game:GetService("UserInputService")
local Con = game:GetService("ContextActionService")
local REPSTOR = game:GetService("ReplicatedStorage")
local VMS = REPSTOR:WaitForChild("Viewmodels")
local equip = false
local ison = false
local holdingFlashlight = false
-- Changeable Settings
------------------------
local FlashlightKey = "F"
local brightness = 0.7
local range = 40
local shadowson = false
------------------------
player.Character:WaitForChild("Humanoid").Died:Connect(function()
holdingFlashlight = true
end)
game.ReplicatedStorage.pickUpFlashlight.OnClientEvent:Connect(function()
holdingFlashlight = true
end)
repeat
wait()
until holdingFlashlight == true
local maincf = CFrame.new(0, 0, 0)
equip = true
arms = VMS:WaitForChild("v_FlashlightV2"):Clone()
arms.HumanoidRootPart.SpotLight.Brightness = brightness
arms.HumanoidRootPart.SpotLight.Range = range
arms.HumanoidRootPart.SpotLight.Shadows = shadowson
arms.Parent = cam
arms.Name = "Arms"
run.RenderStepped:Connect(function()
if equip == true and arms then
arms:SetPrimaryPartCFrame(
cam.CFrame
* maincf
)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode[FlashlightKey] and equip == true then
if ison == true then
ison = false
arms.HumanoidRootPart.SpotLight.Enabled = false
FlashlightGui.FlashlightOn.Visible = false
FlashlightGui.FlashlightOff.Visible = true
arms.HumanoidRootPart.Flashlightss:Play()
else
ison = true
arms.HumanoidRootPart.SpotLight.Enabled = true
FlashlightGui.FlashlightOff.Visible = false
FlashlightGui.FlashlightOn.Visible = true
arms.HumanoidRootPart.Flashlightss:Play()
end
end
end)
local de = true
function onButtonPress()
if de == true and equip == true then
de = false
if ison == true then
ison = false
arms.HumanoidRootPart.SpotLight.Enabled = false
FlashlightGui.FlashlightOn.Visible = false
FlashlightGui.FlashlightOff.Visible = true
arms.HumanoidRootPart.Flashlightss:Play()
else
ison = true
arms.HumanoidRootPart.SpotLight.Enabled = true
FlashlightGui.FlashlightOff.Visible = false
FlashlightGui.FlashlightOn.Visible = true
arms.HumanoidRootPart.Flashlightss:Play()
end
wait(.75)
de = true
end
end
Con:SetImage("FlashLight", "rbxassetid://2883826635")
Con:BindAction("FlashLight",onButtonPress,true,"F")
--[[ game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
equip = false
ison = false
arms:Destroy()
end) ]]--
This is my entire script (Taken from a tutorial)
I have tried to comment out the last part that disables it when you die, but for some reason it’s still being disabled when you die. Can someone help me?