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

How do I add a delay to this head follow mouse script?

This localscript makes the head follow the mouse, and I was wondering how I'd add a dealy to it. Here's the script:

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:wait() ; Character = Player.Character
local Torso = Character:WaitForChild'Torso'
local Neck = Torso:WaitForChild("Neck")

local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.AutoRotate = false
local HMR = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

local RC0 = CFrame.new(1, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
local RC1 = CFrame.new(-.5, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)

local LC0 = CFrame.new(-1, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
local LC1 = CFrame.new(.5, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

local NeckC0 = Neck.C0
local NeckC1 = Neck.C1

game:GetService("RunService").RenderStepped:connect(function()
	local cf = workspace.CurrentCamera.CFrame.lookVector.Y
	
	Neck.C0 = NeckC0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0, 0):inverse()
	HMR.CFrame = CFrame.new(HMR.Position, Vector3.new(Mouse.Hit.p.x, HMR.Position.Y, Mouse.Hit.p.z))
end)

So let me explain what I mean by a delay, I mean I need it to not start like 1 second after the player joins but rather that the head updates its angle with a 1 second delay. So please don't comment "jUsT uSe WaIt(1)"

2 comments

0

If you add wait(1) at line 23, it actually should do what you want.

0

Actually your answer also worked, thanks

2 answers

✓ Accepted answer

If I have understood your script correctly, you could simply just change the RenderStepped to a while wait(1) do.

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:wait() ; Character = Player.Character
local Torso = Character:WaitForChild'Torso'
local Neck = Torso:WaitForChild("Neck")

local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.AutoRotate = false
local HMR = Character:WaitForChild("HumanoidRootPart")

local Mouse = Player:GetMouse()

local RC0 = CFrame.new(1, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
local RC1 = CFrame.new(-.5, .5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)

local LC0 = CFrame.new(-1, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
local LC1 = CFrame.new(.5, .5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)

local NeckC0 = Neck.C0
local NeckC1 = Neck.C1

while wait(1) do
    local cf = workspace.CurrentCamera.CFrame.lookVector.Y

    Neck.C0 = NeckC0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0, 0):inverse()
    HMR.CFrame = CFrame.new(HMR.Position, Vector3.new(Mouse.Hit.p.x, HMR.Position.Y,
    Mouse.Hit.p.z))
end

5 comments

0

or just do while true do

0

Wait, so should I just replace that entire line with while wait(1) so

0

I have updated my post, it'd look like that I believe.

0

Wait, let me try it. It looks promising

0

Worked like a charm, I'm just gonna use some lerping and adjust the numbers because it's a bit choppy. Thanks though.

I'm not very sure what you mean unless you say putting a

wait()

you could also put a cooldown like this:

local cooldown = 1
wait(cooldown)

Or do

while true do
-- the rest of your script here
wait(1)
end

5 comments

0

Ok, so what I mean is, when I move my mouse around the screen, the character's head moves towards the mouse to look at that direction INSTANTLY. I want it to have a 1 second delay.

0

then im not sure i can help

0

try what i edited

0

ok

0

That just broke the script

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