on the saveTable Table the code doesnt detect SwordsFolder help.
local dataserice = game:GetService("DataStoreService")
local data = dataserice:GetDataStore("Data")
local function savedata(player)
local saveTable = {
player.SwordFolder.BegPunch.Value;
player.SwordFolder.IntPunch.Value
}
local success, errormessage = pcall(function()
data:SetAsync(player.UserId, saveTable)
end)
if success then
print("saved the bool")
else
warn(errormessage)
end
end
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "SwordFolder"
local bpunch = Instance.new("BoolValue", folder)
bpunch.Name = "BegPunch"
local inpunch = Instance.new("BoolValue", folder)
inpunch.Name = "IntPunch"
bpunch.Changed:Connect(function()
savedata()
end)
end)
game.Players.PlayerAdded:Connect(function(player)
savedata()
end)
I’m not entirely sure but I believe you are calling “SwordFolder” before it is created/defined. maybe try moving the function after you create the folder.
local dataserice = game:GetService("DataStoreService")
local data = dataserice:GetDataStore("Data")
local function savedata(player)
local saveTable = {
player.SwordFolder.BegPunch.Value;
player.SwordFolder.IntPunch.Value
}
local success, errormessage = pcall(function()
data:SetAsync(player.UserId, saveTable)
end)
if success then
print("saved the bool")
else
warn(errormessage)
end
end
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "SwordFolder"
local bpunch = Instance.new("BoolValue", folder)
bpunch.Name = "BegPunch"
local inpunch = Instance.new("BoolValue", folder)
inpunch.Name = "IntPunch"
bpunch.Changed:Connect(function()
savedata(player)
end)
end)
game.Players.PlayerAdded:Connect(function(player)
savedata(player)
end)
You aren’t passing the player argument to the function at all, so the player variable there is nil, also the event should be PlayerRemoving not PlayerAdded!
Instead, you should do:
game.Players.PlayerRemoving:Connect(function(player)
savedata(player) --player is passed to the function!
end)
or even better:
game.Players.PlayerRemoving:Connect(savedata)
which will automatically pass all the event parameters(in this case, the player) to the savedata function.
Also don’t separate values with semicolons, this is a syntax error(I think), instead separate them with commas:
local saveTable = {
player.SwordFolder.BegPunch.Value, --a comma not a semicolon!
player.SwordFolder.IntPunch.Value
}
Other issues with your code include:
saveTable isn’t a dictionary, for player-related data dictionaries are ideal and caring about space isn’t needed because datastores offer 4MB of space per key.
you aren’t fetching the data when the player is added, so their data will start from nothing again and be saved as is so you basically erase their data every time they join the game.
you should save data when the player leaves, not every time the in-game values change, else you will be rate limited by the Roblox datastores API.
Also, your code has a lot of more complicated data store issues but for those open-source libraries such as ProfileService exist. In general, it’s a good practice not to reinvent the wheel, especially when messing with important things like player data.
Lastly, due to a large number of errors in your code, I assume it may be AI-generated, don’t trust AI for serious issues such as data stores.