Made this GUI opening effect for my “horror” game titled LIDDY. The entire game isn’t really final and is just a concept, so nothing you see is particularly finished.
Video
Code
-- // Copyright 2023, AutumnsBlanket, All rights reserved.
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local dialogue = {}
local playerGui = Players.LocalPlayer.PlayerGui
local dialogueBox = playerGui:WaitForChild("Dialogue")
local queue = {}
local currentDialogue = nil
local isPlaying = false
local targetGuiPosition = UDim2.new(0.5, 0, 0.9, 0)
local targetGuiSize = UDim2.new(0.5, 0, 0, 100)
-- Updated tweens for open-up and close effects
local openTween = TweenService:Create(dialogueBox.Box, TweenInfo.new(0.25), {Position = targetGuiPosition, Size = targetGuiSize})
local closeTween = TweenService:Create(dialogueBox.Box, TweenInfo.new(0.25), {Position = targetGuiPosition, Size = UDim2.new(0.5, 0, 0, 0)})
local function playNextDialogue()
if #queue > 0 then
currentDialogue = table.remove(queue, 1)
local characterName = currentDialogue.characterName
local text = currentDialogue.text
local bindable = currentDialogue.bindable
local textBox = dialogueBox.Box:WaitForChild("Text")
local nameBox = dialogueBox.Box:WaitForChild("Name")
textBox.MaxVisibleGraphemes = 0
textBox.Text = text
nameBox.Text = string.upper(characterName) .. ":"
openTween:Play() -- Play open-up effect
openTween.Completed:Wait()
for i = 1, string.len(text) do
textBox.MaxVisibleGraphemes = i
dialogueBox.TextPlay:Play()
task.wait(0.07)
end
task.wait(1)
closeTween:Play() -- Play close effect
closeTween.Completed:Wait()
bindable:Fire()
isPlaying = false
-- Play the next dialogue
playNextDialogue()
else
currentDialogue = nil
dialogueBox.Enabled = false -- Hide the dialogue box when the queue is finished
end
end
local function addDialogueToQueue(characterName, text, bindable)
table.insert(queue, {
characterName = characterName,
text = text,
bindable = bindable
})
if not isPlaying and not currentDialogue then
isPlaying = true
dialogueBox.Enabled = true -- Show the dialogue box when new dialogue is triggered
playNextDialogue()
end
end
function dialogue.New(characterName, text, bindable)
addDialogueToQueue(characterName, text, bindable)
end
return dialogue