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

Why am I unable to move eyes with head?

Asked by 2 years ago

I am making a game and Im using cframe.lookat to make the npc look at the character, the head has small, red, neon balls as children of the head but when I move the head using the script below it doesn't move the eyes with it.

01RunService = game:GetService("RunService")
02game.Players.PlayerAdded:Wait()
03 
04plr = game.Players:GetChildren()
05 
06for _, Player in plr do
07 
08    plr = Player
09    break
10 
11end
12 
13character = plr.Character or game.Players[plr.Name].CharacterAdded:Wait()
14 
15game.Workspace:WaitForChild("NPC")
View all 27 lines...

1 answer

Log in to vote
0
Answered by 2 years ago

You can use WeldConstraints to glue the eyes on the head.

1-- This should be a Normal Script inside the NPC
2local NPC = script.Parent
3local Head = NPC.Head
4local Eyes = Head.Eyes -- change this if it has a different name
5 
6local weld = Instance.new("WeldConstraint", Head)
7weld.Part0 = Head
8weld.Part1 = Eyes

I edited the script to make the script look organized. I also made it that if you make it a LocalScript the eyes will only move in the player's screen if they move just like Seek's eyes in Doors.

Also you don't need to use RunService.Heartbeat since task.wait() functions the same way.

01-- This should be a LocalScript inside StarterPlayer.StarterCharacterScripts
02local Character = script.Parent
03local Head = Character:WaitForChild("Head")
04 
05local NPC = workspace:WaitForChild("NPC")
06local NPCHead = NPC:WaitForChild("Head")
07local NPCHeadCFrame = NPCHead.CFrame
08 
09while true do
10    NPCHead:PivotTo(CFrame.lookAt(NPCHeadCFrame.Position, Head.CFrame, NPCHeadCFrame.UpVector))
11 
12    task.wait()
13end
0
Yes thank you but now i'm trying to use collection service to make a lot of them look at the character at once but i cant figure out how. PeterParker17386 16 — 2y
0
You mean multiple NPCs looking at the same person? T3_MasterGamer 2189 — 2y
Ad

Answer this question