How can I make my shop better and exploit-free?
Asked by
6 years ago Edited 6 years ago
Keep in mind that I'm a beginner at developing roblox games and have started to understand how codes work generally.
In my game: one of the major parts of the game is to make the shop system efficient and secure. Of course I have to make all features secure.
So far I've come up with this kind of shop system. In which the purchase event runs with the button(Currently this works for coins only. I haven't made the system check what kind of currency is going to be used yet)
When the buy button is pressed, the display price(display is supported with Ui with a script designed for the shop system itself. This menas there's going to be many scripts) is going to be subtracted from the players price. If the player doesn't have enough coins, a frame will pop up telling them. Else, It's going to do as the code does. After that, the corresponding item Ui with a script designed for the equipment system will be cloned to the weapon equipment scrolling frame.
It also comes with an addition of telling if the player has bought the item. I used a folder to make sure that everything which was bought is going to the specific folder.
(localscript)
03 | local Player = game.Players.LocalPlayer |
04 | local leaderboard = Player:WaitForChild( "leaderstats" ) |
07 | local RS = game:GetService( "ReplicatedStorage" ) |
10 | local EFolder = game.ReplicatedStorage:WaitForChild( "EventsFolder" ) |
11 | local CPurchase = EFolder:WaitForChild( "CoinsPurchase" ) |
12 | local OweItem = EFolder:WaitForChild( "OwnedItem" ) |
13 | local Affordable = EFolder:WaitForChild( "OwnedItem" ) |
17 | local button = script.Parent |
18 | local price = script.Parent.Parent.Price |
19 | local thisName = script.Parent.Parent.ItemNameview |
20 | local Purchased = script.Parent.Parent.PurchasedLabel |
23 | local BoughtItems = game.ReplicatedStorage.BoughtItems |
27 | button.MouseButton 1 Click:Connect( function () |
28 | game.ReplicatedStorage.EventsFolder.CoinsPurchase:FireServer() |
30 | if leaderboard.Coins.Value > = price.Value then |
31 | leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value |
32 | local RSItem = RS:WaitForChild(thisName.Text) |
33 | RSItem:Clone().Parent = BoughtItems |
34 | local ThisUI = game.ReplicatedStorage.UIStore:WaitForChild(thisName.Text) |
35 | local WeaponEquipment = Player.PlayerGui.Navigations.EquipmentFrame.WeaponsScroller |
36 | ThisUI:Clone().Parent = WeaponEquipment |
39 | if BoughtItems:FindFirstChild(thisName.Text) then |
40 | button.Visible = false |
41 | Purchased.Visible = true |
44 | Purchased.Visible = false |
47 | if leaderboard.Coins.Value < price.Value then |
48 | Player.PlayerGui.Navigations.ShopFrame.InsufficientDisplay.Visible = true |
Here comes the part which I haven't fully understood yet. Using the remoteevents. From what I understand, I have to set up a condition, which in this case is when I press the purchase button. When that condition triggers, I have to tell the remote event what to do. I think whatever code I write in the onserverevent is what I code I want to become legit. Do I think right?
02 | local EFolder = game.ReplicatedStorage.EventsFolder |
05 | local RS = game:GetService( "ReplicatedStorage" ) |
08 | local CPurchase = EFolder.CoinsPurchase |
09 | local GPurchase = EFolder.GemsPurchase |
13 | CPurchase.OnServerEvent:Connect( function (player) |
15 | local Player = game.Players.LocalPlayer |
16 | repeat wait() until Player |
17 | local leaderboard = Player:WaitForChild( "leaderstats" ) |
18 | local price = Player.PlayerGui.Navigations.ShopFrame.ShopPreviewFrame.Price |
19 | local thisName = Player.PlayerGui.Navigations.ShopFrame.ShopPreviewFrame.ItemNameview |
20 | local BoughtItems = game.ReplicatedStorage.BoughtItems |
21 | local button = Player.PlayerGui.Navigations.ShopFrame.ShopPreviewFrame.BuyButton |
22 | local Purchased = Player.PlayerGui.Navigations.ShopFrame.ShopPreviewFrame.PurchasedLabel |
25 | if leaderboard.Coins.Value > = price.Value then |
26 | leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value |
27 | local RSItem = RS:WaitForChild(thisName.Text) |
28 | RSItem:Clone().Parent = BoughtItems |
29 | local ThisUI = game.ReplicatedStorage.UIStore:WaitForChild(thisName.Text) |
30 | local WeaponEquipment = game.Players.LocalPlayer.PlayerGui.Navigations.EquipmentFrame.WeaponsScroller |
31 | ThisUI:Clone().Parent = WeaponEquipment |
34 | if BoughtItems:FindFirstChild(thisName.Text) then |
35 | button.Visible = false |
36 | Purchased.Visible = true |
39 | Purchased.Visible = false |
42 | if leaderboard.Coins.Value < price.Value then |
43 | game.StarterGui.Navigations.ShopFrame.InsufficientDisplay.Visible = true |
Is there any way to improve the whole entire thing? Leave comments below.