local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local npc = workspace.FriendlyNPC
local ClickDetector = npc:FindFirstChild("ClickDetector")
local GUI = player.PlayerGui:WaitForChild("NPCGUI")
local Frame = GUI:WaitForChild("DialogueFrame")
local Dialogue = Frame:WaitForChild("Dialogue")
local startPos = UDim2.new(0.25, 0, 1.5, 0)
local endPos = UDim2.new(0.25, 0, 0.8, 0)
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.In
)
local startProperties = {
Position = endPos
}
local endProperties = {
Position = startPos
}
local tweenIn = tweenService:Create(Frame, tweenInfo, startProperties)
local tweenOut = tweenService:Create(Frame, tweenInfo, endProperties)
local speed = 0.04
local isTyping = false
local skip = false
local debounce = false
local CasualDialogue = {
"Hey! What brings you here?",
"Howdy friend, how are you?",
"Yo what's up?!",
"Woah, I haven't seen you in forever!? How have you been?"
}
local SadDialogue = {
"The weather today is terrible!",
"The birds around here are so annoying, I just want some peace and quiet!",
"Today is the worst day ever!",
"I am in such a bad mood right now, this day can't get any worse!"
}
local HappyDialogue = {
"Lovely weather today isn't it?",
"I love listening to the birds chirp around here.",
"Today is the best day ever!",
"I am in a really good mood right now!"
}
local function msgDecider()
local randomTable = math.random(1, 3)
local currentTable
if randomTable == 1 then
currentTable = CasualDialogue
elseif randomTable == 2 then
currentTable = SadDialogue
else
currentTable = HappyDialogue
end
local message = currentTable[math.random(1, #currentTable)]
return message
end
local function sendMessage(message)
if debounce then return end
debounce = true
skip = false
isTyping = true
Dialogue.Text = ""
task.wait(0.5)
for i = 1, #message do
if skip then
Dialogue.Text = message
break
end
Dialogue.Text = string.sub(message, 1, i)
task.wait(speed)
end
isTyping = false
end
mouse.Button1Down:Connect(function()
if Frame.Position == startPos then return end
if isTyping then
skip = true
else
tweenOut:Play()
debounce = false
end
end)
ClickDetector.MouseClick:Connect(function()
if debounce then return end
tweenIn:Play()
sendMessage(msgDecider())
end)
#Relatively new to scripting, any way of scripting this easier? 115 lines seems like a drag.
1 messages · Page 1 of 1 (latest)
Its good enough man
its good, noting else to do
The only way i can think of improving it would be using module scripts but those are fairly more advanced
alr
aight
yeah i wasnt gonna use them because this wasnt supposed to be a larger project
i was expecting a single table and no viewports just an npc system but then more ideas kept popping up
I might move it all into a module script if i can be asked