So, I’m attempting to load my game which is a hub of sorts, which will lead the player into another place, the game itself serves as a start place and its supposed to save Kills and Wipe-outs through the games, the hub will convert to points and place you on a leader board depending on how many you have, but I have a small issue, when I try to load my points counter comes up as a “?” which is set this way by default in case anything goes wrong which it has.
I cannot travel through my games on roblox nor on studio, I’m trying to test out my KOs and WOs saving between games and I cant teleport, nor will any data show up at all.
I’ve looked all over the developer hub for this specific error and I’ve come to learn its because a certain variable or something doesn’t exist.
As for the error that is outputted, it says this:
Loaded data of XShockwaveX2335 - Server - BackendMain:449
ServerScriptService.BackendMain:511: attempt to index nil with 'KOs' - Server - BackendMain:511
Stack Begin - Studio
Script 'ServerScriptService.BackendMain', Line 511 - function PlayerAdded - Studio - BackendMain:511
Stack End - Studio
Infinite yield possible on 'Players.XShockwaveX2335:WaitForChild("Points")' - Studio
Stack Begin - Studio
Script 'Players.XShockwaveX2335.PlayerGui.MainUI.UIHandler', Line 1351 - function Init - Studio - UIHandler:1351
Script 'Players.XShockwaveX2335.PlayerGui.MainUI.UIHandler', Line 1358 - Studio - UIHandler:1358
Stack End - Studio
As for teleporting, no error is outputted and I have no clue why it wont let me switch between all of the games under the start place. I can only assume it has something to do with this I’m relatively new to scripting so this may be a challenge. I appreciate any effort towards helping <3
Could be an issue to do with the actual data itself. The error attempt to index nil with "KOs" might be to do with the data not saving properly, not loading properly, not having enough time to save before the game closes, or not using the DataStoreService properly. Are you:
Using a BindToClose() function to ensure the game has enough time to save data
Using the same key to save and load data, within the same DataStore
Using a pcall() to access the DataStore
Labelling all the data correctly within your data dictionary
As for data keys and labelling the data correctly in a dictionary, this is my first proper attempt at using a datastore, so I’m unsure weather or not I had to set up something beforehand, I’m guessing by keys you mean what they are named?
No, I meant like the item you put as the first parameter to GetAsync() and SetAsync(), as well as UpdateAsync(). Anything within the DataStore for an individual player. An example might be: "Key_"..player.UserId
Also, the FindFirstChild() part within the SetAsync() function needs to be changed. FindFirstChild() should be used when you are unsure whether something exists or not. Since it is a server-side script, change it to the following:
local playerPoints = player.Points.Value
local succ, err = pcall(function()
Points:SetAsync(tostring(Player.UserId), playerPoints)
end)
Plus, if you are only testing this in Studio, your BindToClose() function is ignoring that which could still mean there’s not enough time for saving the data.
Not at all, every time I have tried to test it and my print statements never print anything but "print("Loaded data of “…tostring(Player.Name))”, I have a few tostring lines for certain different datastores, such as banned players, play time, and points. The thing that gets printed says that the data is loaded, even when it is not. I publish after editing the script, and go on to the games page on the website and run it from there, and the same issue happens.
That seems to be working great! Thank you! My data now loads, which is good progress, but I still seem to have issues while moving throughout places, my data doesn’t save withing place to place, I reset character to get a WO in the other place and it doesn’t save over, any idea how I can achieve this? I mean my KOs and WOs should move from the game under the starter place, and transfer the data over to the start place (the hub) so that it can calculate the KOs and WOs and convert them into points. Is it as simple as copying the script from serverscriptservice and placing it in the other places serverscriptservice?
I may have jumped the gun a bit asking that question so soon, so is that as simple as just copying over the main script from serverscriptservice where all the datahandlers are stored. Also it seems another error has popped up…
I’m fairly certain it is, i replaced all of the FindFirstChild() functions with what you provided. I’m starting to believe that I cant teleport while the data is this way