Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I stop my character facing my mouse?

I have this script, which you obviously know from the title, makes your character face your mouse. It works amazing, but I don't know how to stop it when I want it to. I tried disconnecting it since it's in a bindable event, and I tried disabling the script as well, but that doesn't work as well. I think you need to change the cframe back to normal, in order to make it stop. But how do I do that? Someone please help!!

Script that does the thing

local conn
conn = game.ReplicatedStorage.MouseFacing.Event:Connect(function(run)
    local player = game.Players.LocalPlayer
    local character = player.Character
    if not character or not character.Parent then
        character = player.CharacterAdded:wait()
        local tor = character:WaitForChild("HumanoidRootPart")
        local hum = character:WaitForChild("Humanoid")
    end
    local cam = game.Workspace.CurrentCamera
    local equipped = false
    local tor = character.  HumanoidRootPart
    local hum = character.Humanoid
    player.CharacterAdded:Connect(function()
        character = player.Character
        tor = character:WaitForChild("HumanoidRootPart")
        hum = character:WaitForChild("Humanoid")
    end)
    local Mouse = player:GetMouse()
    local prev_mousehit
    if not run then
        hum.AutoRotate = false
        tor.CFrame = CFrame.new(tor.Position, Vector3.new(Mouse.Hit.p.x,tor.Position.y,Mouse.Hit.p.z))
    end
    if run then 
        game:GetService("RunService").RenderStepped:Connect(function()
            if (cam.Focus.p-cam.CoordinateFrame.p).magnitude > 1 then
                hum.AutoRotate = false
                if Mouse.Hit.p ~= prev_mousehit then

                    prev_mousehit = Mouse.Hit.p tor.CFrame = CFrame.new(tor.Position, Vector3.new(Mouse.Hit.p.x,Mouse.Hit.p.y,Mouse.Hit.p.z))
                end
            else
                hum.AutoRotate = true
            end 
        end)
    end
end)

1 comment

0

NOTE: This script is parented to StarterPlayerScripts

1 answer

You already saved your connection to a variable, so just do :Disconnect()

If that doesn't work because that's a server script and the client is already replicating the movements of the Character to the server and that's completely unnecessary then you'd have to disable whatever is rotating the Character on the client.

4 comments

0

It's a local script, and I already have tried to disconnect it. It doesn't work for some reason.

0

Disconnect always works, make sure another script isn't changing the position of the character.

0

However on line 26, you do make another connection to RunService (looks like a potential memory leak to me), that actually rotates the character, disconnect that as well.

0

Tried disconnecting that as well, didn't work, and I don't have any other scripts that changes the position of the character.

This discussion is preserved as it was. New answers, comments, and votes are closed.