Hello.
Within my game, I have a menu that has a Play TextButton with a LocalScript inside of it that upon clicking it the TextButton, it tells three other LocalScripts to enable themselves (originally start off disabled). Once it is clicked, these three LocalScripts effectively turn the camera into a third person shooter type camera. This is so that the player can move his/her mouse around in the menu without it being locked in the center of the screen.
The three LocalScripts are CameraScript, MouseLock, and RotateChar.
CameraScript is the script that actually makes the third person camera, MouseLock is the script that puts the mouse in the center of the screen, and RotateChar makes the player face the center of the screen at all times.
However, when the player dies, the three LocalScripts continue to work. The MouseLock script that keeps the mouse in the center of the screen is still on and so is the third person camera script.
I’ve tried looking for solutions on how to solve this, and I’ve done multiple testing in Studio of different ways to solve it, but have had no success.
How would I go about having these LocalScripts stop working on the death of a player and have the default camera settings instead?
CameraScript LocalScript:
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local context = game:GetService("ContextActionService")
local plr = game:GetService("Players").LocalPlayer
local Camera = game:GetService("Workspace").CurrentCamera
local mouse = plr:GetMouse()
local cameraDB = false
local zoomDB = false
local xAngle = 0
local yAngle = 0
local cameraPos = Vector3.new(2,0,8.5)
wait(0.01)
Camera.CameraType = Enum.CameraType.Scriptable
context:BindAction("CameraMovement", function(_,_,input)
xAngle = xAngle - input.Delta.x*0.4
yAngle = math.clamp(yAngle - input.Delta.y*0.4,-80,80)
end, false, Enum.UserInputType.MouseMovement)
rs.RenderStepped:Connect(function()
local c = plr.Character or plr.CharacterAdded:Wait()
local rootPart = c:FindFirstChild("HumanoidRootPart")
if c and rootPart then
local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)
local cameraCFrame = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,cameraPos.Z))
local cameraFocus = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X,cameraPos.Y,-50000))
Camera.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
end
end)
MouseLock LocalScript:
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
RotateChar LocalScript:
local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function()
if plr.Character then
local rootPart = plr.Character:WaitForChild("HumanoidRootPart")
if rootPart then
rootPart.CFrame = CFrame.new(rootPart.CFrame.p, rootPart.CFrame.p + Vector3.new(cam.CFrame.LookVector.X,0,cam.CFrame.LookVector.Z))
end
end
end)