What I wanted to achieve is after a Player triggers a cutscene, an NPC would be cloned from Replicated Storage to the workspace and would annoyingly follow the Player around with a BodyPosition.
The Issue is that the Body Position does change but it doesn’t necessarily follow the player. However, if it’s parented to the workspace at first then it functions.
BodyPosition Changing as the AI doesn’t function as intended: https://gyazo.com/cd64e27f0e2739a752db0ed71b270ecf
AI not functioning as intended: https://gyazo.com/24479c055013362819034c28a2f3e7c5
AI functioning in workspace: https://gyazo.com/3955daf0b9fd84dbf8e96b95456c1cbf
I’ve tried to swap the BodyPosition with a BodyVelocity but the results were still the same - minus the NPC moving upwards.
https://gyazo.com/684c079cf7be8010a25f2a58ef8296db
NPC AI Script:
local NPC_Rig = script.Parent
local Humanoid = NPC_Rig.Humanoid
local RootPart = NPC_Rig.PrimaryPart
local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = Vector3.new(0, math.huge, 0)
BodyPosition.Name = "FlightPosition"
BodyPosition.Parent = RootPart
function FindTarget()
local MaximumDistance = math.huge
local Target = nil
for index, Character in pairs(workspace:GetChildren()) do
if Character:FindFirstChild("Humanoid") then
if (Character.PrimaryPart.Position - RootPart.Position).Magnitude < MaximumDistance then
Target = Character.PrimaryPart
Humanoid.WalkToPoint = Target.Position
end
end
end
return Target
end
while wait(0.1) do
local Target = FindTarget()
if Target then
BodyPosition.Position = Humanoid.WalkToPoint
Humanoid:MoveTo(Humanoid.WalkToPoint)
end
end
Entrance Event Script:
local EnemyEvents_Folder = game.ReplicatedStorage.EnemyEvents
local GoblinEntrance_Event = EnemyEvents_Folder.GoblinEnterEvent
local CutsceneRigs_Folder = game.ReplicatedStorage.CutsceneRigs
local Goblin_Rig = CutsceneRigs_Folder["Green Goblin"]
local Green_Goblin = game.ReplicatedStorage["Green Goblin"]
local Music_Folder = workspace.Music_Tracks
local City_Music = Music_Folder.City_Music
local Boss_Music = Music_Folder.Boss_Music
GoblinEntrance_Event.Event:Connect(function(Player)
local Cutscene_Goblin = Goblin_Rig:Clone()
Cutscene_Goblin.Parent = workspace
local EntranceAnim = Cutscene_Goblin.Humanoid:LoadAnimation(Cutscene_Goblin.Entrance)
EntranceAnim:AdjustSpeed(0.3)
City_Music:Stop()
Boss_Music:Play()
wait(4)
Green_Goblin.Parent = workspace
Cutscene_Goblin:Destroy()
end)
Touched Event Script:
--//Event Variables & Replicated Storage\\--
local Events_Folder = game.ReplicatedStorage.CutsceneEvents
local CameraEvent = Events_Folder.CutsceneCamEvent
local ReturnEvent = Events_Folder.ReturnCamEvent
local EnemyEvents_Folder = game.ReplicatedStorage.EnemyEvents
local GoblinEntrance_Event = EnemyEvents_Folder.GoblinEnterEvent
--//Workspace Variables & Debounce\\--
local Cameras_Folder = workspace.CutsceneCameras
local TriggerPart = script.Parent
local Debounce = false
--//Touched Event\\--
TriggerPart.Touched:Connect(function(hit)
if not Debounce and hit.Parent:FindFirstChild("Humanoid") then
local Character = hit.Parent
local RootPart = Character:FindFirstChild("HumanoidRootPart")
if RootPart then
RootPart.Anchored = true
end
CameraEvent:FireAllClients(Cameras_Folder.GoblinEntryCam1.CFrame)
GoblinEntrance_Event:Fire(game.Players:GetPlayerFromCharacter(hit.Parent))
Debounce = true
wait(2)
CameraEvent:FireAllClients(Cameras_Folder.GoblinEntryCam2.CFrame)
wait(2)
ReturnEvent:FireAllClients()
if RootPart then
RootPart.Anchored = false
end
end
end)