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

How to make this function stop? "title should be specific"

Asked by
Neon_N 104
6 years ago

The script below is Localscript and is in StarterCharacterScript.

wait(1)
local player = game.Players.LocalPlayer
local character = player.Character
local torso = character.HumanoidRootPart 
local mouse = player:GetMouse()

character.Humanoid.AutoRotate = false

mouse.Move:connect(function()
    torso.CFrame = CFrame.new(torso.Position, mouse.Hit.p*Vector3.new(1,0,1) + torso.Position*Vector3.new(0, 1, 0))
end)

How do I make the script stop working after a few seconds? and if you look at other direction while walking, humanoid tries to look at direction they are walking. How do I fix both of the problem?

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Hi. What you're asking for is disconnecting the event listener from the Move event. This can be done by defining the connection as a variable, and then using :Disconnect() on it, like so:

local ev = mouse.Move:Connect(function()
    --stuff
end)
wait(5)
ev:Disconnect()

Additionally, if you want to prevent the character from looking in another direction, place a BodyGyro under Torso or UpperTorso, set its MaxForce to inf on the Y axis (Vector3.new(0,math.huge,0)), and then, instead of setting the HumanoidRootPart's CFrame, set the CFrame of BodyGyro (make sure to remove it afterwards).

0
Kiriot can you help me on my post below his on questions tab most recent devwitwiki -28 — 6y
0
No because I don't get what you're asking for in your question, devwitwiki Amiaa16 3227 — 6y
0
It's updated bro devwitwiki -28 — 6y
Ad

Answer this question