Im trying to make a modulescript where it can equip and remove a tower, but somehow, it doesn’t create the 2nd attribute in line 72?
--[[
a - lam
]]
local module = {}
local serverscriptservice = game:GetService('ServerScriptService')
local profileservice = require(serverscriptservice.Services.ProfileService)
local players = game:GetService('Players')
local cachedProfiles = {}
local key = '!34w@!'
local dataformat = {
[1] = 'Warrior',
[2] = 'Slingshooter',
[3] = nil,
[4] = nil,
[5] = nil
}
local equipDatastore = profileservice.GetProfileStore('equipdatastore',dataformat)
local function loadData(player)
local profile = cachedProfiles[player]
local folder = Instance.new('Folder')
folder.Name = 'towersEquipped'
folder.Parent = player
for i, v in ipairs(profile.Data) do
if v ~= nil then
local foo = v..'Lvl0'
local val = Instance.new('ObjectValue')
val.Value = game.Workspace.Dictionary.Units[v]['LEVEL0'][foo]
val.Parent = folder
val.Name = i
val:SetAttribute('order',i)
end
end
end
function module:startModule(player)
local profile = equipDatastore:LoadProfileAsync(player.UserId..key,'ForceLoad')
if profile ~= nil then
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick('Your data has been loaded remotely, Please rejoin.')
end)
if players:FindFirstChild(player.Name) then
cachedProfiles[player] = profile
loadData(player)
end
else
player:Kick('Unable to load tower data, Please rejoin.')
end
end
function module:equipTower(player,tower)
local profile = cachedProfiles[player]
local equippedTowers = player:FindFirstChild('towersEquipped')
if profile ~= nil and #equippedTowers:GetChildren() ~= 5 then
if equippedTowers:FindFirstChild(tower):GetAttribute('tower') ~= tower then
local place = #equippedTowers:GetChildren() + 1
local foo = tower..'Lvl0'
local val = Instance.new('ObjectValue')
val.Value = game.Workspace.Dictionary.Units[tower]['LEVEL0'][foo]
val.Parent = equippedTowers
val.Name = place
val:SetAttribute('order',place)
val:SetAttribute('tower',tower)
profile[place] = tower
else
return false
end
elseif profile ~= nil and #equippedTowers:GetChildren() == 5 then
local place = equippedTowers:FindFirstChild(5)
local foo = tower..'Lvl0'
place.Value = game.Workspace.Dictionary.Units[tower]['LEVEL0'][foo]
profile[place] = tower
end
end
function module:unequipTower(player,slot,tower)
local profile = cachedProfiles[player]
local equippedTowers = player:FindFirstChild('towersEquipped')
if profile ~= nil and slot then
equippedTowers:FindFirstChild(slot):Destroy()
profile[slot] = nil
elseif profile ~= nil and not slot and tower then
for i, v in ipairs(equippedTowers:GetChildren()) do
if v:GetAttribute('tower') == tower then
v:Destroy()
profile[i] = nil
end
end
end
end
players.PlayerRemoving:Connect(function(player)
local profile = cachedProfiles[player]
if profile ~= nil then
profile:Release()
end
end)
game:BindToClose(function()
for _, v in ipairs(players:GetChildren()) do
local profile = cachedProfiles[players]
if v:IsA('Player') and profile ~= nil then
profile:Release()
end
end
end)
return module