Hello so my problem is when I equip my sword it should put me in kind of a shift lock state but the problem is idk how to snap the player to look the way the cameras facing heres a video
see the problem is it can lock sideways and stuff when I want it to lock facing forward how can I do this
heres my camera code:
local uis = game:GetService("UserInputService")
local swordEquipped = false
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = true
local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0
local offset = Vector3.new(3, 3, 10)
game.ReplicatedStorage.Events.swordCameraMovementEquipped.OnClientEvent:Connect(function()
swordEquipped = true
end)
game.ReplicatedStorage.Events.swordCameraMovementUnEquipped.OnClientEvent:Connect(function()
swordEquipped = false
end)
uis.InputChanged:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
x = x - input.Delta.X
y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
if swordEquipped == true then
hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0) --This is what turns the player when looking around the problem is with the autorotate
end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) *
CFrame.Angles(math.rad(y), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
end)
heres my sword script that turns auto rotate to false and will freeze the player still like that:
--//Locals
local player = script.Parent.Parent.Parent
local char = player.Character
local event = game.ReplicatedStorage.Events.swordCameraMovementEquipped
local event2 = game.ReplicatedStorage.Events.swordCameraMovementUnEquipped
--//Main
script.Parent.Equipped:Connect(function()
print("Katana equipped!")
char.Humanoid.AutoRotate = false
event:FireClient(player)
end)
script.Parent.Unequipped:Connect(function()
print("Katana un-equipped!")
char.Humanoid.AutoRotate = true
event2:FireClient(player)
end)
tool.Equipped:Connect(function())
equipped = true
end)
tool.Unequipped:Connect(function())
equipped = false
end)
RunService.Heartbeat:Connect(function()
if equipped then
characterHumanoidRootPart.CFrame = characterHumanoidRootPart.CFrame * CFrame.new(characterHumanoidRootPart.Position, (mouseHit.X, characterHumanoidRootPart.Position.Y, mouseHit.Y)
end
end)
Also, do note that you shouldn’t be disabling auto-rotate for situations like this, the auto-rotate bool value only determines whether the character should rotate the direction they are moving.
Yes im disabling it to give it kinda an effect like in Dead by daylight but for pvp I want it to be like shift lock but thanks for your response I will check this out.
tool.Activated:Connect(function()
if characterHumanoidRootPart then
characterHumanoidRootPart.CFrame = CFrame.new(characterHumanoidRootPart.Position, (mouseHit.X, characterHumanoidRootPart.Position.Y, mouseHit.Y)
end
end)
Remove the Equipped and Unequipped events!
I get an error on the mouseHit.X i can fix the error by removing the ( right before it idk why its even there but even without it you guys are giving to much info and it will give me an error saying that it doesnt work as well as ducking I do not know where to put this script because I do not know how to get mouse.Hit on the server
Oh, you’re doing this on the server, I thought you were doing this on the client. Anyways, I recommend doing all of this in the client, if you want the player to rotate to the mouse position on the server, It will be delayed and it’ll look terrible.
I am doing it in the client sorry for the confusion I just never used mouse.Hit but when i did it it gave me a couple errors and I couldnt fix the script the script didnt really work for me
repeat wait() until game:IsLoaded()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
tool.Equipped:Connect(function())
equipped = true
end)
tool.Unequipped:Connect(function())
equipped = false
end)
RunService.Heartbeat:Connect(function()
local mouseHit = mouse.Hit.p
if equipped then
characterHumanoidRootPart.CFrame = characterHumanoidRootPart.CFrame * CFrame.new(characterHumanoidRootPart.Position, (mouseHit.X, characterHumanoidRootPart.Position.Y, mouseHit.Y)
end
end)
on the comma on mouseHit.X, it erros expected ‘)’ to close ‘(’ at colum 54 I can fix this error by removing the second bracket like it says but then I get an error saying Im putting to much info into the parameters.