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

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

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

✓ Accepted answer

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).

3 comments

0

Kiriot can you help me on my post below his on questions tab most recent

0

No because I don't get what you're asking for in your question, devwitwiki

0

It's updated bro

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