Answered by
3 years ago Edited 3 years ago
Problem
Yes, we need to use DataStoreService.
Solution
We don't need to create the BoolValue Instance, we can simply store a bool value in DataStores.
When using Data Stores you always need to use a pcall AKA protected call because Roblox DataStores can fail sometimes.
Fix
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
04 | local DataStore_CodeName = DataStoreService:GetDataStore( "RedeemCode" , "CodeName" ) |
05 | local DataStore_CodeName 2 = DataStoreService:GetDataStore( "RedeemCode" , "CodeName2" ) |
07 | local CodeRedeemed = game.ReplicatedStorage.CodeEvent |
10 | local function OnCodeRedeemed(Client, Code) |
14 | if Code = = "CodeName" then |
16 | Success, Result = pcall ( function () |
17 | return DataStore_CodeName:GetAsync(Client.UserId) |
21 | if Success and not Result then |
22 | Client.leaderstats.Points.Value + = 100 |
24 | Success, Result = pcall ( function () |
25 | DataStore_CodeName 2 :SetAsync(Client.UserId, true ) |
35 | if Code = = "CodeName2" then |
37 | Success, Result = pcall ( function () |
38 | return DataStore_CodeName 2 :GetAsync(Client.UserId) |
42 | if Success and not Result then |
43 | Client.leaderstats.Points.Value + = 250 |
45 | Success, Result = pcall ( function () |
46 | DataStore_CodeName 2 :SetAsync(Client.UserId, true ) |
58 | CodeRedeemed.OnServerEvent:Connect(OnCodeRedeemed) |
EXPLOITING PROBLEM
I've found a way to easily exploit your game.
I see that you passed a Reward argument through the RemoteEvent.
So I can exploit it with an executor and do this
1 | game.ReplicatedStorage.CodeEvent:FireServer( 1000000 , "CodeName" ) |
And there we go, I just gave myself 1M points.
So how do we fix this?
Just don't pass stuff like that to the server and do the rewarding on the server.
You can understand DataStores here. It explains everything about DataStoreService and how you can use it. BTW, you don't need to read the whole article all at once. You can read bit by bit otherwise, you'll get overwhelmed.
If there's any problems with the code, you can reply to me in the comments on my answer.
You should play around with DataStores too, so you can understand and feel comfortable using them.