#lookAt and PivotTo not actually facing player

1 messages · Page 1 of 1 (latest)

fierce rose
#

When im running this script, it seems to make the face of the head whatever was already facing the player when they spawned in, rather than the actual face of it facing the player at all times.

This script is going to handle multiple head trackings, so that's why it is setup like this.

Anybody know a fix for this?

#
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local pHead = character:WaitForChild("Head")

----------- MAIN LOOP -------------

game:GetService("RunService").RenderStepped:Connect(function()
    local targetPos = pHead.Position
    
-- SHADOW FREDDY --

    local shadowFreddy = workspace.Map.Map:WaitForChild("shadowFreddyPAS")
    
    local sFHead = shadowFreddy.up:WaitForChild("head")
    local sFHeadPivot = sFHead:GetPivot()
    local sFHeadPos = sFHeadPivot.Position
    local sFFollow = CFrame.lookAt(sFHeadPos, targetPos, Vector3.new(0,1,0))
    sFHead:PivotTo(sFFollow)
    
    
end)

lethal compass
#

From a quick read the code itself looks fine, do you have anything else that modifies any part of freddy at any point?

fierce rose
#
-- Managing the fading in and out --

local shadowFreddy = workspace.Map.Map.shadowFreddyPAS
local SFPrimary = shadowFreddy:WaitForChild("broworkpls")

local tweenService = game:GetService("TweenService")

local player = game.Players.LocalPlayer

---- LOOP :P -----------

game:GetService("RunService").RenderStepped:Connect(function()
    local character = player.Character
    local hrp = character:WaitForChild("HumanoidRootPart")

    local dist = (SFPrimary.Position - hrp.Position).Magnitude
    if dist > 25 then
        for _, parts in ipairs(shadowFreddy:GetDescendants()) do
            if parts:IsA("BasePart") then
                tweenService:Create(parts, TweenInfo.new(.5), {Transparency = 1}):Play()
            end
        end
    else
        for _, parts in ipairs(shadowFreddy:GetDescendants()) do
            if parts:IsA("BasePart") then
                tweenService:Create(parts, TweenInfo.new(.5), {Transparency = 0}):Play()

            end
        end
    end
end)
#

This is the script that manages that

lethal compass
fierce rose
#

oh?

lethal compass
fierce rose
#

Just like, his head model in the explorer?

lethal compass
# fierce rose oh?

Step through the code in your head — every frame its checking if your greater than or less than 25 studs away from freddy, and then playing a tween

lethal compass
fierce rose
lethal compass
fierce rose
lethal compass
fierce rose
lethal compass
fierce rose
fierce rose
lethal compass
# fierce rose So should I use something like a boolvalue?

That might work
-# Assuming you mean use a BoolValue and listen to its Changed event. I think it would work but i'm not 100% sure if the change event would actually fire even if you assign the value that the BoolValue already contains.
It would be more efficient to remember the last value in a variable and compare it each time you check the distance
Something like this

local was_close
game:GetService("RunService").RenderStepped:Connect(function()
    local dist = -- Do calculation

    local is_close = dist > 25

    -- If the character hasn't changed from being close or far
    -- since the last frame, don't do any tweens
    if is_close == was_close then return end

    if is_close then
        for _, parts in ipairs(shadowFreddy:GetDescendants()) do
            if parts:IsA("BasePart") then
                tweenService:Create(parts, TweenInfo.new(.5), {Transparency = 1}):Play()
            end
        end
    else
        for _, parts in ipairs(shadowFreddy:GetDescendants()) do
            if parts:IsA("BasePart") then
                tweenService:Create(parts, TweenInfo.new(.5), {Transparency = 0}):Play()

            end
        end
    end
end)

And just for completness, here is the same code but cleaned up a bit

local tween_info = TweenInfo.new(.5)
local was_close
game:GetService("RunService").RenderStepped:Connect(function()
    local dist = -- Do calculation

    local is_close = dist > 25

    -- If the character hasn't changed from being close or far
    -- since the last frame, don't do any tweens
    if is_close == was_close then return end

    local transparency = if is_close then 1 else 0
    for _, part in shadowFreddy:GetDescendants() do
      if part:IsA("BasePart") then
        tweenService:Create(part, tween_info, {Transparency = transparency}):Play()
      end
  end
end)