What does the code do and what are you not satisfied with?
The code makes variables for my story game that make potential limits and overall direct the user’s gameplay, most of these variables are interactions with NPCs. I’m not satisfied with how it looks and overall how much work I had to put into this script .
What potential improvements have you considered?
I’ve considered modularizing and using tables but I don’t know how I would implement them in this situation.
How (specifically) do you want to improve the code?
I want to make it look more neat and easy to change. I’m guessing if I were to change this it would result in make change things line by line and I don’t think that’s right.
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local events = RS:WaitForChild("ActivationEvents")
local start = events:FindFirstChild("Start")
local function playerAdded(plr)
local quests = Instance.new("Folder", plr)
local talkedto = Instance.new("Folder", plr)
local TimoTalk = Instance.new("BoolValue", talkedto)
local RaymondTalk = Instance.new("BoolValue", talkedto)
local FeliciaTalk = Instance.new("BoolValue", talkedto)
local LauraTalk = Instance.new("BoolValue", talkedto)
local RubyTalk = Instance.new("BoolValue", talkedto)
local JuliusTalk = Instance.new("BoolValue", talkedto)
local JerichoTalk = Instance.new("BoolValue", talkedto)
local interaction = Instance.new("BoolValue", plr)
local InQuest = Instance.new("BoolValue", plr)
local quest1 = Instance.new("BoolValue", quests)
local quest2 = Instance.new("BoolValue", quests)
talkedto.Name = "TalkedTo"
RaymondTalk.Name = "RaymondTalk"
FeliciaTalk.Name = "FeliciaTalk"
JerichoTalk.Name = "JerichoTalk"
RubyTalk.Name = "RubyTalk"
RaymondTalk.Name = "RaymondTalk"
TimoTalk.Name = "TimoTalk"
JuliusTalk.Name = "JuliusTalk"
InQuest.Name = "InQuest"
quests.Name = "Quests"
quest1.Name = "Quest1"
quest2.Name = "Quest2"
interaction.Name = "Interacting"
interaction.Value = false
start:FireClient(plr)
end
players.PlayerAdded:Connect(playerAdded)
local players = game:GetService(“Players”)
local RS = game:GetService(“ReplicatedStorage”)
local events = RS:WaitForChild(“ActivationEvents”)
local start = events:FindFirstChild(“Start”)
local function playerAdded(plr)
local quests = Instance.new(“Folder”, plr)
local talkedto = Instance.new(“Folder”, plr)
local TimoTalk = Instance.new(“BoolValue”, talkedto)
local RaymondTalk = Instance.new(“BoolValue”, talkedto)
local FeliciaTalk = Instance.new(“BoolValue”, talkedto)
local LauraTalk = Instance.new(“BoolValue”, talkedto)
local RubyTalk = Instance.new(“BoolValue”, talkedto)
local JuliusTalk = Instance.new(“BoolValue”, talkedto)
local JerichoTalk = Instance.new(“BoolValue”, talkedto)
local interaction = Instance.new(“BoolValue”, plr)
local InQuest = Instance.new(“BoolValue”, plr)
local quest1 = Instance.new(“BoolValue”, quests)
local quest2 = Instance.new(“BoolValue”, quests)
talkedto.Name = “TalkedTo”
RaymondTalk.Name = “RaymondTalk”
FeliciaTalk.Name = “FeliciaTalk”
JerichoTalk.Name = “JerichoTalk”
RubyTalk.Name = “RubyTalk”
RaymondTalk.Name = “RaymondTalk”
TimoTalk.Name = “TimoTalk”
JuliusTalk.Name = “JuliusTalk”
InQuest.Name = “InQuest”
quests.Name = “Quests”
quest1.Name = “Quest1”
quest2.Name = “Quest2”
interaction.Name = “Interacting”
interaction.Value = false
start:FireClient(plr)
end
You can create the instances beforehand and then just clone them into the player, something like this
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local events = RS:WaitForChild("ActivationEvents")
local start = events:FindFirstChild("Start")
local function playerAdded(plr)
for _, v in pairs(script.StarterPlayerInstances:GetChildren()) do
v:Clone().Parent = plr
end
start:FireClient(plr)
end
players.PlayerAdded:Connect(playerAdded)