I want to be able to have the players only obtain this orb once, but when i run this code and try to have it save it errors out
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 |
03 | local orb 1 datastore = DataStoreService:GetDataStore( "Orb1DataStore" ) |
04 |
05 | |
06 |
07 | game.Players.PlayerAdded:Connect( function (player) |
08 |
09 | local orb 1 value = Instance.new( "IntValue" ) |
10 |
11 | orb 1 value.Name = "orb1" |
12 |
13 | orb 1 value.Parent = player |
14 |
15 | local data |
16 |
17 | local success, errormessage pcall ( function () |
18 |
19 | data = orb 1 datastore:GetAsync(player.UserId.. "orb1" ) |
20 |
21 | end ) |
22 |
23 | if success then |
24 |
25 | orb 1 value.Value = data |
26 |
27 | else |
28 |
29 | print ( "There was an error with getting your orb1 data" ) |
30 |
31 | warn(errormessage) |
32 |
33 | end |
34 |
35 | end ) |
36 |
37 | |
38 |
39 | game.Players.PlayerRemoving:Connect( function (player) |
40 |
41 | local success, errormessage pcall ( function () |
42 |
43 | orb 1 datastore:SetASync(player.UserId.. "orb1" ,player.orb 1. Value) |
44 |
45 | end ) |
46 |
47 | if success then |
48 |
49 | print ( "Orb1 data successfully saved" ) |
50 |
51 | else |
52 |
53 | print ( "There was an error while saving orb1 data" ) |
54 |
55 | warn(errormessage) |
56 |
57 | end |
58 |
59 | end ) |
I believe this will work:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 |
03 | local orb 1 datastore = DataStoreService:GetDataStore( "Orb1DataStore" ) |
04 |
05 | |
06 |
07 | game.Players.PlayerAdded:Connect( function (player) |
08 |
09 | local orb 1 value = Instance.new( "IntValue" ) |
10 |
11 | orb 1 value.Name = "orb1" |
12 |
13 | orb 1 value.Parent = player |
14 |
15 | local data |
16 |
17 | local success, errormessage pcall ( function () |
18 |
19 | data = orb 1 datastore:GetAsync(player.UserId.. "orb1" ) |
20 |
21 | end ) |
22 |
23 | if success then |
24 |
25 | orb 1 value.Value = data |
26 |
27 | else |
28 |
29 | print ( "There was an error with getting your orb1 data" ) |
30 |
31 | warn(errormessage) |
32 |
33 | end |
34 |
35 | end ) |
36 |
37 | |
38 |
39 | game.Players.PlayerRemoving:Connect( function (player) |
40 |
41 | local success, errormessage pcall ( function () |
42 | if player:FindFirstChild( "orb1" ) then else print ( "Ok your values are noobs" ) return end |
43 |
44 | orb 1 datastore:SetASync( tostring (player.UserId).. "orb1" ,player:FindFirstChild( "orb1" ).Value) |
45 |
46 | end ) |
47 |
48 | if success then |
49 |
50 | print ( "Orb1 data successfully saved" ) |
51 |
52 | else |
53 |
54 | print ( "There was an error while saving orb1 data" ) |
55 |
56 | warn(errormessage) |
57 |
58 | end |
59 |
60 | end ) |