LockInFirstPerson Mouse will not work

So I made a script where you can move your mouse when your in first person, and it works. But when your character dies, it stops working for no reason. How can I fix this?

btw here is the script (LocalScript in StarterPlayerScripts):

local plrGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")


local screenGui = Instance.new("ScreenGui", plrGui)

local txtButton = Instance.new("TextButton")
txtButton.BackgroundTransparency = 1
txtButton.Size = UDim2.new(0, 0, 0, 0)

txtButton.Modal = true

txtButton.Parent = screenGui

papahetfan

1 Like

consider putting it in startergui, its because player scripts only run once and not on spawn, and when you respawn your gui gets reset.

2 Likes

I believe that your issue may be that the screenGui isn’t recreated post death. Toggling the property “ResetOnSpawn” may fix it.

1 Like

Heres the code with reset on spawn set to false

local plrGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

local screenGui = Instance.new("ScreenGui", plrGui)
screenGui.ResetOnSpawn = false
local txtButton = Instance.new("TextButton")
txtButton.BackgroundTransparency = 1
txtButton.Size = UDim2.new(0, 0, 0, 0)

txtButton.Modal = true

txtButton.Parent = screenGui

Thank you very very very very much!