Best way to go about tree system?

I want to create a tree system in which the player can activate a proximity prompt on the tree and have objects fall out from it; those objects will be collectibles (e.g. apples and oranges) only on the specific client that activated the tree.

Right now I do all the math and cooldowns on the server when the tree is activated:

 -- self.Instance is the tree.

    local Prompt = self.Instance.PrimaryPart.Prompt.ShakePrompt

     self._Trove:Add(Prompt.Triggered:Connect(function(Player)
        if not self.PlayersCooldown[Player] then
            self.PlayersCooldown[Player] = os.time() - self.CooldownTime
        end

        if os.time() - self.PlayersCooldown[Player] >= self.CooldownTime then
            self.ItemData[Player.Name] = {}

            local RandomAmount = self.Random:NextInteger(1, 3)
        
            for _ = 1, RandomAmount do
                table.insert(self.ItemData[Player.Name], self:RollCollectable())
            end
        
            print(self.ItemData) -- {dmksa123 = {[1] = Orange, [2] = Apple}}
            Generate:FireClient(Player, self.ItemData[Player.Name], self.Instance.PrimaryPart.CFrame)

            self.PlayersCooldown[Player] = os.time()
        end
    end))

However, on the client, I want to generate the objects/collectibles. The problem I am facing is that I have no way to prevent duplication of the object by exploiters.

self._Trove:Connect(Generate.OnClientEvent, function(ItemData: {}, TreeCFrame: CFrame)
        for _, Item in ItemData do
            if self.Instance.Name == Item then
                local ClonedObject = self.Instance:Clone()
                ClonedObject.Parent = workspace

                ClonedObject:PivotTo(TreeCFrame * CFrame.new(math.random(1, 3), 3, math.random(1, 3)))
            end
        end
    end)

I want the client to send information back to the server that removes the collectible from their ItemData (as shown in the module).

The solution I was thinking about was just to send back a client → server RemoteEvent to remove the objects from their ItemData and check if the object is in the data still.

Basically, I desire to know if this is the best way to handle this or if there is a better way.

Sorry to bump, but there have yet to be any suggestions.

If I’m understanding this correctly then what you’re doing currently should be fine.

Should flow something like this:

PlayerA triggers prompt → on the server you generate a table with the items and quantity for the respective player. e.g:

self.GeneratedItems[Player.UserId] = {
      Apples = 1;
      Bananas = 4;
      Mangos = 7;
};

→ send this data to the players client in order to generate the visuals and prompts for them to pick it up. → when PlayerA picks up 2 Bananas → fire a remote to the server saying PlayerA is attempting to pickup 2 banana’s → verify that there are 2 or more Bananas in the generatedItems list → remove 2 Bananas from the list → tell client to remove any visuals for the 2 Bananas.

Now let’s say an exploiter tries to spoof the system and tells the server he wants 1 carrot. → when the server checks the list it sees theres no carrots and ignores the request. Same would apply if the player tries to pick up more items then the available quantity.

As for players triggering multiple trees that they aren’t near. Just make a distance check → check the magnitude between the player and the tree and make sure they’re within reasonable range.

Hopefully I understood what you meant.

Yes, this is exactly what I am doing, thank you for your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.