Hi, so i’ve made a ModuleScript
to change my character’s expression via a simple function in it called Expressions:Swap()
. I’ve also made it so that the Mouth is always facing the Camera using a function which is then put into a RunService.RenderStepped
function from another script. The problem is that the Mouth only switches to the correct mouth side image when the :Swap()
function is called. I wanna make it always face the Camera no matter what. Does that make sense? I don’t know honestly, it’s really confusing me! Help, please.
--||Services
local Players = game:GetService("Players")
--||Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local EyebrowsV = {
Character:WaitForChild("LeftEyebrow").GUI,
Character:WaitForChild("RightEyebrow").GUI
}
local EyesV = {
Character:WaitForChild("LeftEye").GUI,
Character:WaitForChild("RightEye").GUI
}
local MouthV = Character:WaitForChild("Mouth").GUI
local MouthSide
--------------------------------------
local Expressions = {}
--||Functions
function Expressions:MouthFaceCamera(Root, Camera)
local ViewDistance = (Root.Position - Camera.CFrame.Position).Unit
local Dot = ViewDistance:Dot(Root.CFrame.RightVector)
if Dot > -1 and Dot < 0 then
MouthSide = "Left"
elseif Dot < 1 and Dot > 0 then
MouthSide = "Right"
end
end
--------------------------------------
function Expressions:Swap(Eyebrows: string, Eyes: string, Mouth: string, Expression: string)
Character:SetAttribute("Expression", Expression)
for _, Eyebrow : SurfaceGui in ipairs(EyebrowsV) do
for _, Image : ImageLabel in ipairs(Eyebrow:GetChildren()) do
if Image.Name ~= Eyebrows then
Image.Visible = false
else
Image.Visible = true
end
end
end
--------------------------------------
for _, Eye : SurfaceGui in ipairs(EyesV) do
for _, Image : ImageLabel in ipairs(Eye:GetChildren()) do
if Image.Name ~= Eyes then
Image.Visible = false
else
Image.Visible = true
end
end
end
--------------------------------------
for _, Image : ImageLabel in ipairs(MouthV:GetChildren()) do
if not string.match(Image.Name, Mouth) or not string.match(Image.Name, MouthSide) then
Image.Visible = false
elseif string.match(Image.Name, Mouth) and string.match(Image.Name, MouthSide) then
Image.Visible = true
end
end
end
--------------------------------------
return Expressions