Did you add the swordFolder to the player in another script?
no the same script
char limit ykykyk
you aren’t putting the player as an argument in the function…
Are you adding the swordFolder in a playerAdded event?
Edit:ignore what I said I didn’t see the playerAdd event
I overlooked the script. @vyexon is absolutely correct. you have “player” as an argument in the function but never call it with the function.
then whats the solution for that
at the end:
game.Players.PlayerAdded:Connect(function(player)
savedata()
end)
add player to your savedata function seen here:
game.Players.PlayerAdded:Connect(function(player)
savedata(player)
end)
same here.
bpunch.Changed:Connect(function()
savedata(player)
end)
that doesnt work either rips iii
may I see your current script?
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)
it cant find the SwordFolder
what is the error you are encountering? and also try using savedata() within the first PlayerAdded event. you are calling the event twice.
it cant find the SwordFolder thats the error
yes but what is the error exactly? it should give you a line. are you able to type it out or screenshot it?
it cant find it inside the table in the function
which line is giving the error?
You have two instances of this event hook. Are you certain which one fires first, or do they fire simultaneously?
You should never have two hooks to the same event defined in a single script. Change it to this;
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)
savedata();
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.
i feel like getting my code called Ai generated is the worst insult i could ever get, regardless, thanks for your help
lol yeah
simple mistakes we do everyday