This is my first time making a quest gui script and I wanted to know if there are ways to make the code cleaner, fluid, and overall optimized. Heres my script:
local stg = game:GetService("StarterGui")
local ts = game:GetService("TweenService")
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
print('triggered')
local frame = plr.PlayerGui.QuestGui["Quest#1"]:FindFirstChild("DialogFrame")
local questframe = plr.PlayerGui.QuestGui["Quest#1"]:FindFirstChild("QuestFrame")
local sounds = game:GetService("ReplicatedStorage").ClonedSounds["Typewriter 2 (SFX)"]
local label = frame.Dialog
local no = frame.Nah
local yes = frame.Yes
plr.PlayerGui.QuestGui.Enabled = true
local slow = 0.1
label.MouseButton1Click:Once(function(input)
print('touching')
slow = 0
end)
if plr.PlayerGui.QuestGui.Enabled then
print('true')
frame.Visible = true
for i, v in pairs(frame:GetChildren()) do
if v:IsA("TextButton") then
v.Text = ""
end
end
local function typewrite(obj, text)
for i = 1, #text do
task.wait(slow)
obj.Text = string.sub(text, 1, i)
sounds:Play()
end
end
local function confirmation(obj)
if obj == no then
print('no')
plr.PlayerGui.QuestGui.Enabled = false
elseif obj == yes then
print("Yeah")
questframe.Visible = true
frame.Visible = false
end
end
typewrite(label, "Can you kill 5 rigs for me?")
if label.Text == "Can you kill 5 rigs for me?" then
typewrite(no, "Nah I dont wanna")
typewrite(yes, "HECK YEAH!")
end
no.MouseButton1Click:Once(function()
confirmation(no)
end)
yes.MouseButton1Click:Once(function()
confirmation(yes)
end)
end
end)
use module scripts for type write effects Functions
2.Use Remote Events for a communication between server to client
3.use a Dictonary to store different texts as a key and the value will be a function depending on the outcome yoy want
Also say you had a huge amount of proximity prompts or an object that will give you quest it would be better to connect those to a remote event so the server requests something to happen on the client side.In Addition,You could use CollectionService to tag proximity prompts or objects related so its more efficient using only one script to handle tagging objects.
it’s pretty much increasing network load, remote event is useless if OP don’t want to perform server logic, proximity prompts can work on server and they are fine
Your code is unredable, you don’t use cases for variable names, also some are unclear, like obj or label
My tips:
Don’t localize player in proximity prompt, you can do it on top of the script if it’s all on client
Use full names TweenService, not ts or DialogFrame, not label
Try to not use annonymous functions as they are unclear what they do
Don’t hard-code your quests, i see your script only can work with one quest
Try to separate functions into modules, if you need to pass objects via connection, you can do something like at the bottom of current script, where you use annonymous function that calls other function
I’ve made scripting tutorial for advanced topics, and some of them might help you create quest system, here is link if you want: Advanced Scripting Tutorial
Remember that refactoring is common practice, and rewriting code to be cleaner is good
True! You are going to be increasing the networkload so it would be better to let the client side handle the quest but wouldnt you want to at least verify on the server that the client completed a quest on the server using a RemoterFunction.
I have actually made a part 2 to this post since I took your suggestions and implemented them into my quest system also I want to know what I can do to make those modules have effecient code heres the link: