So I have the following piece of code and the CharacterAdded is not firing, is it because of the vertical order? I mean calling LoadCharacter() before declaring the CharacterAdded event.
game.Players.PlayerAdded:Connect(
function(Player)
local Profile = BaseProfile:Clone();
Profile.Name = Player.Name
Profile.Parent = Profiles
PlayerId = Player.userId;
local PlayerData = DataBase:GetAsync(PlayerId);
DataSlots = Profile:GetChildren();
if PlayerData then
print("Data Received!")
for Key, Value in pairs(DataSlots) do
if PlayerData[Value.Name] then
Value.Value = PlayerData[Value.Name]
end
end
Player:LoadCharacter()
else
print("Data Missing")
end
Player.CharacterAdded:Connect(
function(Character)
print("Requesting")
Weld.WeldSword(Character, Profile.Sword.Value)
end
)
end
)
The character is loaded before you begin listening to the event (you :LoadCharacter() then listen for CharacterAdded), therefore the function won’t run.
You can solve this by performing the logic you want after you load the character, i.e:
local function CharacterLoaded(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
print(Character.Name .. " loaded!")
end
game:GetService("Players").PlayerAdded:Connect(function(Player)
Player:LoadCharacter()
CharacterLoaded(Player)
end)