Hey all! I have a pretty good giver script utilizing a Proximityprompt attached to an attachment. The part is in a vending machine that dispenses soda, however, I want players to not have multiple versions of the drink in their inventory. I tried using "player.Backpack:ClearAllChildren() " before the drink is given but if the player holds the can before interacting, they will still get a second soda. The script prevents them from gathering more than two, but how do I fix this?
Soda is held in ReplicatedStorage and cloned, then placed in the players inventory if that makes any difference Thank you! Here is the current script with no changes
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local drinkTool = ReplicatedStorage.Starjuice
local drinkPart = script.Parent
drinkPart.Attachment.ProximityPrompt.Triggered:Connect(function(player) --ProximityPrompt cleared
local drinkCopy = drinkTool:Clone() --Clones drink
player.Backpack:ClearAllChildren() --What is supposed to delete inventory! Problem Area!
drinkCopy.Parent = player.Backpack --Puts drink in inventory
end)

5 comments
lmk if that works
The script still functions good if I don't hold the drink, but it still allows me to get two of them if Im holding the first one that I grab. Using the "clearallchildren" command doesnt seem to work with items you are holding either, so Im unsure how to continue
oh ok
try it now i update it
Hey there! Sorry I didnt see the update till now, it gives syntax error for expecting to close at line 12. Messin with the code atm