Dialogue "opening" effect

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

6 Likes

It looks like it could be a really cool project or game but what i do find funny is you are putting a copyright on your code which even when you say copyright all rights reserved you still don’t have any copyright protection over your code.

1 Like

the copyright protection is put there from a plugin i’ve never bothered to disable. regardless, copyright is still obtained the moment my work is public

the animation is decent but i suggest you make a fade in animation.

Is it? If so please give me the source as i have not known that. I always thought any code released for free is just open source code.

This looks great! However, I’d say maybe try making it a bit smoother

Overall Great Work and keep up the great work!