Implementation then. There’s a couple of issues with your code, so let’s walk through them.
First thing is that skinfolder is an unnecessary upvalue. Move that down into the scope of PlayerAdded.
-- Good practice to index services first, plus this is the canonical way to get a service
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function (Player)
local skinfolder = Instance.new("Folder") -- Do NOT use the Parent argument!
skinfolder.Name = "skinfolder"
skinfolder.Parent = Player
end)
That being said, this implementation could potentially be a little flawed.
Your original code used the parent argument of Instance.new - don’t do that. It’s also worth noticing that you’re putting this folder under the player which is, well, undesirable. You’ll probably understand later as you code but this typically isn’t a comfortable way of storing data. You should typically keep it in ServerStorage under some kind of session data container.
Your code isn’t making full use of the benefits of protected call (pcall). Rather than wrapping your entire code in a pcall, you should only wrap methods that have the potential to fail in a pcall.
You can change that whole line below PlayerAdded:
-- I'm not using the new code I posted before, I'm using your direct code
game.Players.PlayerAdded:connect(function(plr)
local skinfolder = Instance.new("Folder")
skinfolder.Name = "skinfolder"
skinfolder.Parent = plr
-- Wraps GetAsync in protected mode in case it fails
local success, result = pcall(ds.GetAsync, ds, "id-"..plr.UserId) -- userId is deprecated
if success and result then
for _, skin in pairs(skins) do
local newval = Instance.new("BoolValue")
newval.Name = skin
newval.Parent = skinfolder
end
else
-- handle errors (success returns false from the pcall)
end
end)
As far as separating data and not data being saved to wrong players, this should be fine as it is. The next major thing to address is the remote, which has its own respective issues (and even security flaws). At this point, it’s up to you to figure out how to fix it, though I’ll give you a few pointers.
- You shouldn’t automatically handle events when FireServer is called from the client. In this case, the server should have some kind of debouncing of some sort to prevent throttling on your DataStores or pointless waste of the request budget.
- Just like in the code above, try to make full use of pcalls. They aren’t really meant for you to throw anonymous functions where all your code is in a pcall - they’re really meant for wrapping functions that have the potential to fail.
- For some reason, you’re having the remote save twice when it’s called?
The rest should be good after these fixes are made.