I’m not sure what to say the title says it all. Code shouldn’t be to hard to understand. I’m getting all the characters (NPC’s) in a model. Setting the character to NPC. Then updating on key press. I feel like it’s too bulky. If there is any confusion please let me know and I will edit the post.
local NPCCharacters = {}
local CharacterValue = 1
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
for i,v in pairs(workspace.NPCCharacters:GetChildren()) do
table.insert(NPCCharacters, v.Name)
end
wait(.01)
player.Character = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
workspace.CurrentCamera.CameraSubject = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
local function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
if CharacterValue == #NPCCharacters then
CharacterValue = 1
else
CharacterValue = CharacterValue + 1
end
local cloned = player.Character:Clone()
cloned.Parent = workspace.NPCCharacters
player.Character = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
workspace.CurrentCamera.CameraSubject = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
elseif inputObject.KeyCode == Enum.KeyCode.E then
if CharacterValue == 1 then
CharacterValue = #NPCCharacters
else
CharacterValue = CharacterValue - 1
end
local cloned = player.Character:Clone()
cloned.Parent = workspace.NPCCharacters
player.Character = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
workspace.CurrentCamera.CameraSubject = workspace.NPCCharacters:WaitForChild(NPCCharacters[CharacterValue])
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
end)
end)