Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 05:35 PM |
in the modulescript:
function PlayerStatManager:ChangeStat(player, statName, changValue) sessionData[player][statName] = sessionData[player][statName] + changValue end
in a script in serverscriptservice:
-- Require ModuleScript so we can change player stats local PlayerStatManager = require(game.ServerStorage.PlayerStatManager) -- After player joins we'll periodically give the player money and experience game.Players.PlayerAdded:connect(function(player) while wait(2) do PlayerStatManager:ChangeStat(player, 'Testing', 5) end end)
i get this error in both studio and when playing the game:
ServerStorage.PlayerStatManager:21: attempt to perform arithmetic on field '?' (a nil value) |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 05:37 PM |
b1
literally came straight from the wiki and i followed all the instructions. gj roblox wiki. |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 14 Sep 2017 05:38 PM |
| roadblox wiki is bad :weeb: |
|
|
| Report Abuse |
|
|
markjac
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 927 |
|
|
| 14 Sep 2017 05:40 PM |
| roblox wiki is old and no one updates it. |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 05:41 PM |
well, that doesnt help alot :thinking:
can someone help me fix this problem then? I am in my own special hell trying to figure out how 2 datastore. someone could also help me w/ that. it'd be nice. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 14 Sep 2017 05:41 PM |
Where do you define sessionData? Also please be very aware, copying scripts directly from the wiki does *NOT* mean they will work. The wiki generally posts examples instead of fully functional scripts. |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 14 Sep 2017 05:42 PM |
| why don't you actually mess with datastores instead of just using a module from the wiki :thunking: |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 05:44 PM |
@soybeen
local sessionData = {}
i didnt directly copy it, i did it step-by-step looking at the wiki.
@LaeMVP
because "messing around" with datastores doing it by trial and error is a long and worthless process when there's literally an example and whole lesson of it on the wiki itself. :thernking: |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 05:48 PM |
| b, is there any better alternatives or fixes? im looking to implement datastore into my game and idk how. is there any better way to learn how to do it than the apparently horrible roblox wiki? |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 14 Sep 2017 05:51 PM |
trial and error is how you learn stuff and be good at it, looking at examples and that stuff will only get you so far(especially if the example doesn't even work xd) :weeb: |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 14 Sep 2017 05:56 PM |
"long and worthless process" Not true
However, nowhere in here do I see you even mention the DataStore service, so I'm not sure what the wiki has you doing, but you should probably just navigate to the DataStore Service wiki page.
Here is a basic example that doesn't employ pcalls for security. You can learn about pcalls on your own for your next step.
-- in a server script local ds = game:GetService("DataStoreService") local playerData = ds:GetDataStore("PlayerData")
local sessionData = {}
function SaveData(playerId) playerData:SetAsync(player.UserId,sessionData[player.UserId]) end)
game.Players.PlayerAdded:connect(function(player) sessionData[player.UserId] = playerData:GetAsync(player.UserId) end)
game.Players.PlayerRemoving:connect(function(player) SaveData(player.UserID) sessionData[player.UserId] = nil end)
|
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 14 Sep 2017 06:01 PM |
| @OP It's pretty clear from the error that you haven't defined any defaults. The data associated with key "Testing" is nil, so when you attempt to update it (index previous value and add 5) you are operating on a nil value and the output tells you as much. |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 06:19 PM |
@soybeen
datastoreservice was already defined in the modulescript that the script in serverscriptservice required. however i appreciate you trying to help me
@casualist
default values are defined here in the modulescript:
sessionData[player] = { Testings = 0, BusCreds = 0, Experiences = 0, BusStops = 0, Deaths = 0 } |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
| |
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 06:30 PM |
| fixed, was a silly mistake. however the problem is still the same when i correct it. |
|
|
| Report Abuse |
|
|
|
| 14 Sep 2017 06:43 PM |
| The error is probably the same because you've most likely autosaved the old table. Rewrite the code that gets ### ########## so that even if it finds an old save it overwrites it with new values. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 14 Sep 2017 06:44 PM |
| I'd just change the name of the data store and wipe any keys you've created |
|
|
| Report Abuse |
|
|
Sk8erDan
|
  |
| Joined: 22 Mar 2010 |
| Total Posts: 4565 |
|
|
| 14 Sep 2017 06:52 PM |
| ive been trying to figure this out. how do i do it? (wipe keys) |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 15 Sep 2017 06:48 AM |
| Detect if their store has a key inside it named Testings, if so, ######## a blank template to the key of their UserId Buuuut since this is such a new datastore likely containing nothing critical, I'd just rename it and you will have a fresh slate to keep testing. |
|
|
| Report Abuse |
|
|