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

Entire Body Follows Player Instead Of Just Head?

Asked by 5 years ago

trying to get a NPC's head to follow the player and also be able to animate/move. however, when i use this script, the entire body moves (the head is bound to the torso, is that an issue? i don't think so) instead of just the head and the NPC cannot move or animate. "look" is used to default NPC back to position. this may be the issue, as it must default to look a certain direction, but clarification would be sweet.

stats for bodygyro: D = 350, MaxTorque = 2000,2000,2000, P = 3000

stats for bodyposition: D = 1250, MaxForce = 4000,4000,4000, P = 10000, and Position = 0,50,0.

script is below.

local head = script.Parent.Parent.Head
local bgyro = head.BodyGyro
local bposition = head.BodyPosition
local studsaway = 15
local look = game.Workspace.PellyLook

bposition.Position = head.CFrame.p

while wait() do
    for _, v in pairs(game.Players:GetPlayers()) do
        local character = workspace:WaitForChild(v.Name)
        if character then
            local distance = (head.CFrame.p - character.PrimaryPart.CFrame.p).Magnitude
            if distance <= studsaway then
                bgyro.CFrame = CFrame.new(head.CFrame.p, character.PrimaryPart.CFrame.p)
                break
            else
                bgyro.CFrame = CFrame.new(head.CFrame.p, look.CFrame.p)
            end
        end
    end
end
0
Line 11 will error if a player named Part joins the game LOL User#19524 175 — 5y
0
well i'm glad nobody named Part is going to join the game aquadrious 53 — 5y
0
No, I'm saying if you have a part just named "Part" in the workspace it will error User#19524 175 — 5y
0
i've got a part named "Part" in the workspace and i am not getting any errors. everything works same as before. aquadrious 53 — 5y
View all comments (4 more)
0
If a player is named like something stored in workspace (e.g "Part" like incapaz says) it will error LeadRDRK 437 — 5y
0
use "v.Character or v.CharacterAdded:Wait()" instead LeadRDRK 437 — 5y
0
Ye User#19524 175 — 5y
0
ah, understood. still not solving my issue though. aquadrious 53 — 5y

Answer this question