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.
ok so i did get that so i should only use it for testing in studio but use playerremoving in the actual game?
You should be using it for both studio and roblox.
There is a feature on Roblox where you can shutdown servers, this will cause the BindToClose()
function to fire.
For further information, I suggest reading this.
oh ok but i need the function to only affect the person who left
Your PlayerRemoving function will handle that, the BindToClose()
function will fire whenever a studio session completes or the game is shutdown.
If you want a more in depth guide to saving data in data stores, I recommend referring to this.
This explains everything regarding BindToClose()
and .PlayerRemoving
which is what you will need in your case of saving data.
oh i get it now thanks i have a lot of stuff to try tomorrow
If you find that this works, please mark the topic as solved!
I best be off to sleep now.
Farewell.
i cant try them right now so idk if its gonna work but cya lol
ohh wait im stupid, the reason why the player:waitforchild(“aura”) doesnt work is because i looked for it in the player, not the character lol
ok, so here is the script with the equiponjoin now working, but not the saveaura as a get this error:
attempt to index nil with ‘FindFirstChild’
local aura = player.Character:FindFirstChild("Aura"):FindFirstChildWhichIsA("Folder")
new script with equiponjoin working:
local function saveAura(player)
local profile = datamanager.Profiles[player]
local aura = player.Character:FindFirstChild("Aura"):FindFirstChildWhichIsA("Folder") --where i get the error
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, char) --this works
local aurafolder = char:WaitForChild("Aura")
local currentaura = player:WaitForChild("CurrentAura")
if currentaura.Value ~= "" then
aurahandler.EquipAura(player, player.Character, game.ReplicatedStorage.Auras[currentaura.Value])
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveAura(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveAura(player)
end
end)
game.Players.PlayerAdded:Connect(function(player) --this works
player.CharacterAdded:Connect(function(char)
equipOnJoin(player, char)
end)
end)
what am i doing wrong? ik its because the game cant find the character but how can i make it work?
This means that the Character does not exist therefore the :FindFirstChild()
cannot call if there is nothing to call from.
To fix this issue, try and ensure that the players’ character exists and is already loaded. You can do this by:
local character = player.Character or player.CharacterAdded:Wait()
Let me know if this has helped!
but the function is called when the player is leaving, so how can i wait for it to load when its leaving?
Which line is throwing this error?
this line in saveaura:
local aura = player.Character:FindFirstChild("Aura"):FindFirstChildWhichIsA("Folder")
wait what if i save everytime another aura is equipped? wouldnt that work?
I would suggest attempting my previous suggestion to see if that alters the outcome.
alright ill try your idea first
so unfortunately it didnt save but i didnt get any errors