Script that watches nearby players help

So I’ve made a model where you can become it if you simply walk on the big button in-front of the model. The model is named Mama Tattletail so I’ll call it “Mama” from now on. I’ve got her head to watch the nearby players. However there is two problems in which I currently have no idea how to fix. This is the script:

while true do

local minmag = nil

local minply = nil

local mindir = nil

local beingwatched = false

players = game:GetService(“Players”):GetChildren()

for i=1,#players do

char = players[i].Character

if char then

local foundhead = char:FindFirstChild(“Head”)

local foundtorso = char:FindFirstChild(“Torso”)

local foundHumanoidRootPart = char:FindFirstChild(“HumanoidRootPart”)

local foundhum = char:FindFirstChild(“Humanoid”)

if foundhead and foundtorso and foundHumanoidRootPart and foundhum and foundhum.Health > 0 then

local sub = (script.Parent.CFrame.p - foundhead.CFrame.p)

local dir = sub.unit

local mag = sub.magnitude

if not minmag or minmag > mag then

minmag = mag

minply = char:FindFirstChild(“HumanoidRootPart”)

mindir = dir

end

end

end

end

if minply then

if minmag and minmag <= math.huge then

local unit = (script.Parent.Position-minply.Position).unit

unit = Vector3.new(0,0,0)

script.Parent.CFrame = CFrame.new(script.Parent.Position + (unit*-5), Vector3.new(minply.Position.X, script.Parent.Position.Y, minply.Position.Z))

end

end

wait()

end

I want it to rotate slowly, instead of instantly. For example, if I go through her to get behind or on her sides, the head will teleport in my direction instead of slowly rotating my way. The other problem (which is the reason why I made this Topic), how could I make the script ignore the morphed player? Because when I become her with the script active, it will attempt to look at me and make me spin.

Thanks in advance.

1 Like

Use TweenService to help.

Maybe make a table containing the morphed players and whenever they are close to the model, check if the player Is in the table. If it is, ignore it, otherwise, look at it.

2 Likes