hey so im trying to implement a saving system but the part where im having a problem is making it save when the character is being removed (when leaving) and i want to call a function when the character just spawned. please help
server script in serverscriptservice btw
local function saveAura(player)
local profile = datamanager.Profiles[player]
local aura = player.Character:FindFirstChild("Aura"):FindFirstChildWhichIsA("Folder")
if aura then
profile.Data.CurrentAura = aura.Name
player:FindFirstChild("CurrentAura").Value = profile.Data.CurrentAura
print("Successfully saved the aura "..aura.Name.." to "..player.Name..".")
else
profile.Data.CurrentAura = ""
player:FindFirstChild("CurrentAura").Value = profile.Data.CurrentAura
end
end
local function equipOnJoin(player)
local aurafolder = player:WaitForChild("Aura")
local currentaura = player:WaitForChild("CurrentAura")
if currentaura.Value ~= "" then
aurahandler.EquipAura(player, player.Character, game.ReplicatedStorage.Auras[currentaura.Value]) --aurahandler is a module script in replicatedstorage (the equipping function works so thats not the problem)
end
end
game.Players.PlayerRemoving:Connect(function(player)
player.CharacterRemoving:Connect(function(char)
saveAura(player)
end)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
equipOnJoin(player)
end)
end)
currentaura is a value
i also get a orange message thing but idk what it means:
Infinite yield possible on ‘Players.Kyhomi:WaitForChild(“Aura”)’
nvm i can reply i just cant try them, so if u may have found the solution then you cab just tell me what to do on here (u can put multiple ideas for me to try them all)
game.Players.PlayerRemoving:Connect(function(player)
saveAura(player)
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
task.wait(0.33) equipOnJoin(player)
end)
player.CharacterRemoving:Connect(function(char)
saveAura(player)
end)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveAura(player)
end
end)
well on another server script theres a function that spawns a folder named Aura and when an aura is equipped another folder spawns with the same name as the equipped aura
btw does bindtoclose and the other stuff mean that once i close the game on studio its gonna save for everyone? if so what if i want it to save for only the person thats leavng? do i just keep what i did and use the bindtoclose only for testing if it works?
:BindToClose() is a function that is called whenever the server is shutting down. Therefore, leading to all the players being disconnected. Hence we must run through all players data to save it.