Hi, I’m Mega
I thought of this way to create Player Values which seems quite efficient and fast to me. If I wanted to create alot of values inside a Player that included Pets
, Trails
, Weapons
, OtherStuff
having alot of Instance.new()
would create a mess and would be very wordy. Any feedback would be appreciated.
Module Script in a Folder in ServerScriptService
local util = {}
function util:Create(insClass, insName, insParent)
local ins = Instance.new(insClass)
ins.Name = insName
ins.Parent = insParent
return ins
end
function util:MultiCreate(insClass, insParent, ...)
for _, name in ipairs({...}) do
util:Create(insClass, name, insParent)
end
end
return util
A Server Script in ServerScriptService
local Utility = require(script.Parent:WaitForChild("Modules").Utility)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local Pets = Utility:Create("Folder", "Pets", player)
local Trails = Utility:Create("Folder", "Trails", player)
local Weapons = Utility:Create("Folder", "Weapons", player)
local OtherData = Utility:Create("Folder", "OtherData", player)
--//PETS//
Utility:MultiCreate("BoolValue", Pets, "Red", "Blue", "Orange", "Pink", "Green", "Yellow")
--//TRAILS//
Utility:MultiCreate("BoolValue", Trails, "Red", "Blue", "Orange", "Pink", "Green", "Yellow")
--//WEAPONS//
Utility:MultiCreate("BoolValue", Weapons, "LightSaber", "Sword", "Pistol")
--//OTHER-DATA//
Utility:MultiCreate("IntValue", OtherData, "Coins", "Cash", "Kills", "Deaths", "Wins")
end)
If you are wondering about default values, I add them after initializing my DataStores.
Also I am completely aware of Module Datastorage but this post is not related to that.