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

Facing Mouse Does Not Work After Reset?

Asked by 2 years ago
Edited 2 years ago

So, I have made a script that makes the player's character face the cursor, but when I reset, the script just stops working. I have looked all over the internet (even on page 2 of Google) but I have not found anything that fixes this problem. Any help is appreciated!

(For those who were wondering, when I said reset I meant my character.)

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local root = char:WaitForChild("HumanoidRootPart")
local attatchment = Instance.new("Attachment",root)

local orientation = Instance.new("AlignOrientation",root)
orientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
orientation.MaxTorque = math.huge
orientation.Responsiveness = 200
orientation.Attachment0 = attatchment

game["Run Service"].RenderStepped:Connect(function()
    if mouse.Hit and char.Humanoid.Health ~= 0 then
        root:FindFirstChildOfClass("AlignOrientation").CFrame = CFrame.new(root.Position,Vector3.new(mouse.Hit.Position.X,root.Position.Y,mouse.Hit.Position.Z))
    end
end)

0
What do you mean when you reset the script?? theking66hayday 841 — 2y
0
Change game["Run Service"] to game:GetService("RunService"). Wiscript 622 — 2y
0
this is genuinely just a guess, but try adding some code in another script that disables this script once the player dies and re-enables it when they respawn, I heard that scripts just reset once they are turned off to on so I'm guessing if it just restarts each time it could be a solution? asmetics 26 — 2y

Answer this question