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.
01 | RunService = game:GetService( "RunService" ) |
02 | game.Players.PlayerAdded:Wait() |
03 |
04 | plr = game.Players:GetChildren() |
05 |
06 | for _, Player in plr do |
07 |
08 | plr = Player |
09 | break |
10 |
11 | end |
12 |
13 | character = plr.Character or game.Players [ plr.Name ] .CharacterAdded:Wait() |
14 |
15 | game.Workspace:WaitForChild( "NPC" ) |
You can use WeldConstraint
s to glue the eyes on the head.
1 | -- This should be a Normal Script inside the NPC |
2 | local NPC = script.Parent |
3 | local Head = NPC.Head |
4 | local Eyes = Head.Eyes -- change this if it has a different name |
5 |
6 | local weld = Instance.new( "WeldConstraint" , Head) |
7 | weld.Part 0 = Head |
8 | weld.Part 1 = 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 |
02 | local Character = script.Parent |
03 | local Head = Character:WaitForChild( "Head" ) |
04 |
05 | local NPC = workspace:WaitForChild( "NPC" ) |
06 | local NPCHead = NPC:WaitForChild( "Head" ) |
07 | local NPCHeadCFrame = NPCHead.CFrame |
08 |
09 | while true do |
10 | NPCHead:PivotTo(CFrame.lookAt(NPCHeadCFrame.Position, Head.CFrame, NPCHeadCFrame.UpVector)) |
11 |
12 | task.wait() |
13 | end |