Hello, I am currently working on a one-piece game. In particular, the fruit-eating and storing system.
Eating
I am not quite sure how to handle this one. I have been using a DataStore with a value to store my Fruit. However, I’m not sure how I can get the data of the Fruit and if I clicked to the Server without Remote Events so they are not easily exploitable. Does anyone have suggestions on how I could do it?
Personally for me this how a players data should look:
local Data = {
-- Coins, Gems, Belli etc
Fruit = "None", -- Set it "None" by default
}
Now whenever a player eats a fruit it will change the “None” to the fruits name.
local Remote = -- Have a Remote Event here
-- Assuming the fruit is a tool
Tool.Activated:Connect(function()
Remote:FireServer(Tool.Name) -- Assuming Tool.Name is the name of the frui
end)
-- Server Sided
--// Services
local Players = game:GetService("Players")
local Remote = -- Same Remote Event Here
Remote.OnServerEvent:Connect(function(player: Player, FruitName: string)
if player and player:IsDescendantOf(Players) and typeof(FruitName) == "string" then
-- You can add more checks if needed
-- Check Data to see if Fruit Key is "None" else they can't eat it
-- If your using profile Service you can do
local Data = profile.Data.Fruit
if Data and Data == "None" then
Data = FruitName
-- Delete Fruit From player?
else
-- If they already eaten a fruit or data isn't loaded
end
end
end)
Very basic system you should improve by adding more checks and checking if certain fruits exist, for example, having a table full of fruits in the game and checking that whenever the client has sent a remote. This can still be exploited since the player can send any fruit through so I would check where the player got the fruit. If you’re spawning the fruits on the server which you should be I would check if the fruit existed in the game this should limit the exploit of someone sending a random string through the remote event. I’m sure there’s other ways to check to make sure it can’t be exploited but I can’t really think of anything at the moment. Also make sure to save the data after changing it unless you already have a saving method in place. Now that their fruit is in their data whenever a player loads into the game, get their fruit and assign what you need to.
-- Server Sided
--// Services
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- Get their data
if Data.Fruit ~= "None" then
print(Data.Fruit) -- This is their fruit
end
end)