Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Force Shift Lock won't work after respawn. How can I fix this?

Asked by 3 years ago

I made a gun which forces the player to shift lock once equipped. Everything works fine until the character dies. When I equip it, the shift lock still works, but the camera offset. The offset of the character doesn't work. How can I fix this.

I didn't make the force shift lock script. I looked at a dev forum and you could get the shift lock script.

This is the code:

First a local script in StarterPlayerScripts

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local GameSetting = UserSettings().GameSettings
local Run = game:GetService("RunService")
local Last = nil
local LastFirstPerson = false
local Camera = workspace.CurrentCamera
local CamOffset = 2.5
Run.Heartbeat:Connect(function()
    if LastFirstPerson ~= ((Character.Head.Position - Camera.CoordinateFrame.p).magnitude <= 0.5+CamOffset) then --(first person)
        LastFirstPerson = ((Character.Head.Position - Camera.CoordinateFrame.p).magnitude <= 1+CamOffset)
        Humanoid.CameraOffset = (Last and not LastFirstPerson)  and Vector3.new(CamOffset,0,0) or Vector3.new(0,0,0)
    end
    if Last == _G.ForceShiftLock then
        return
    end
    Last = _G.ForceShiftLock
    UIS.MouseBehavior = Last and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default
    GameSetting.RotationType = Last and Enum.RotationType.CameraRelative or Enum.RotationType.MovementRelative
    Humanoid.CameraOffset = Last and Vector3.new(CamOffset,0,0) or Vector3.new(0,0,0)
end)

Then a module script in StarterPlayerScripts with a whole bunch of module scripts.

After that I put a local script in the tool I wanted for it to shift lock it to.

local Tool = script.Parent
Tool.Equipped:Connect(function()
    _G.ForceShiftLock = true
end)
Tool.Unequipped:Connect(function()
    _G.ForceShiftLock = false
end)

Please help :)

Answer this question