Max amount of drinks in player backpack

Hello, I am trying to limit the amount of drinks a player can hold. I currently have 3 scripts that relate to this, however only one is having issues which I will be sharing here. One script is in the ServerScriptService, and its only purpose is to put an IntValue(drink count number) into players upon joining. The second script controls the actual drinking (animation, sound, increase food stat, and subtract 1 from drink count when drank) and is a local script. Lastly the problem child, this script controls the Proximity Prompt, checking if the player has the max amount of drinks and giving the player the drink.

The script works almost as intended. I can pick up 8 drinks, which is the max I have set, and if I try to pick up more than 8 it stays parented to the workspace which is what I want. However, if I drink one and the IntValue count goes to 7 or even below it still wont let me pick up another drink. I have tried setting out 9, drinking 8 of them each individually and the trying to pick up another but it still spits out the “max drinks” print.

I would appreciate any help

here is the script:

local tool = script.Parent.Parent
local prompt = script.Parent.Parent.ProximityPrompt

local touch = script.Parent:WaitForChild(“TouchInterest”)


local maxTool = 8
local toolCount = Player:FindFirstChild("WaterCount")

if toolCount.Value >= maxTool then
	tool.Parent = workspace
	script.Parent.Anchored = true
	print("Max Water")
elseif toolCount.Value < maxTool then
	script.Parent.Anchored = false
	tool.Parent = Player.Backpack
	toolCount.Value = toolCount.Value + 1


1 Like

I can’t find an issue here, try printing the ToolCount after it gets the intValue watercount.
Perhaps it is not subtracting?

Could you provide more information on where this script is and the other scripts.

I just tried that, its adding and subtracting correctly. I called the subtract after I deleted the drink so i fixed it to subtract before deleting the drink but the problem still persists for some reason.

The script you provided is not the issue, instead it lies within this:

Changes in a local script don’t replicate to the server, on the server it stays the same amount therefore causing the issue. You need to use a RemoteEvent and tell the server that a drink has been used, then subtract the drink amount on the server


The script i posted is in the Handle of the drink, and the local script that controls the actual drinking and subtraction is located in the drink itself not in any parts. The script that handles the intvalue is in the server script service.

here are those scripts:

Local script for actual drinking - script works as intended
local Bottle = script.Parent

local slurp = Bottle.slurp

local anim = Bottle.DrinkAnim

local Drank = false

if Drank then

local LocalPlayer = game:GetService("Players").LocalPlayer
local toolCount = LocalPlayer:FindFirstChild("WaterCount")

Drank = true

local char = Bottle.Parent
local hum = LocalPlayer.Character.Humanoid
local animtrack = hum:LoadAnimation(anim)


game.ReplicatedStorage.Drink:FireServer() -- related to an event that controls food bar gui
toolCount.Value = toolCount.Value - 1


script that controls the IntValue adding upon joining - located in ServerScriptStorage

local WaterCount ="NumberValue", Player)
WaterCount.Name = "WaterCount"
WaterCount.Value = 0

local EnergyCount ="IntValue", Player)
EnergyCount.Name = "EnergyDrinkCount"
EnergyCount.Value = 0


1 Like

ahh okay that makes sense. all along i thought that one was working as intended but as it turns out it was the problem lol
I will implement this and give an update

Update: that was the solution! I added another event to the local script and added a script into the serverscriptstorage that changes the value upon drinking and now it is working beautiful! thank you all for your help I really appreciate it :slight_smile:

1 Like

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