Needing assistance with juice/drink system

As of now i am trying to create a clean working cup drinking system which allows the user to touch a part to receive a cup and then after while holding the cup to touch a bottle and then the cup becomes a drink.

As of now the cup has successfully been transferred to the players inventory.
BUT the liquid part is scattered all over the map on the floor which confuses me right now.

I have tried anchoring the liquid parts or making them invisible and then trying to make them visible once the bottles have been touched but nothing seems to work.

As of now the Cup is a tool named CupModel with a handle part and 11 parts that are supposed to be liquids named Liquid1 till 11. Placed in Replicated storage.

i also have 11 bottles part named Bottle1 till 11 with clicking detectors.
and also a part named CupPickup to receive the cups with a script.

The script in CupPickup for now is

-- Script inside the CupPickup Part
local cupPickup = script.Parent
local clickDetector = cupPickup:FindFirstChild("ClickDetector")
local cupModel = game.ReplicatedStorage:FindFirstChild("CupModel")

-- Check if CupModel exists
if not cupModel then
    warn("CupModel not found in ReplicatedStorage.")
    return
end

local function onClicked(player)
    -- Check if the player has a Backpack
    local backpack = player:FindFirstChild("Backpack")
    if not backpack then
        warn("Backpack not found for " .. player.Name .. ".")
        return
    end
    
    -- Check if the player already has a cup
    if backpack:FindFirstChild("Cup") then
        print("Player " .. player.Name .. " already has a cup.")
        return
    end
    
    -- Clone the cup tool from ReplicatedStorage and put it in the player's inventory
    local cupTool = cupModel:Clone()
    if not cupTool then
        warn("Failed to clone CupModel.")
        return
    end
    
    -- Add cup to player's inventory
    cupTool.Parent = backpack
    print("Cup added to inventory for " .. player.Name .. ".")
end

if clickDetector then
    clickDetector.MouseClick:Connect(onClicked)
else
    warn("ClickDetector not found in CupPickup.")
end

-- Function to handle adding liquid to the cup
local function addLiquid(bottleClicked)
    if not cupModel then
        warn("CupModel not found.")
        return
    end
    
    local cupInstance = cupModel:Clone()
    if not cupInstance then
        warn("Failed to clone CupModel.")
        return
    end
    
    local cupLiquid = cupInstance:FindFirstChild("Liquid" .. bottleClicked)
    if not cupLiquid then
        warn("Liquid" .. bottleClicked .. " not found in CupModel.")
        return
    end
    
    -- Hide all liquids in the cup
    for _, liquid in ipairs(cupInstance:GetChildren()) do
        if liquid.Name:match("^Liquid") then
            liquid.Transparency = 1
        end
    end
    
    -- Show the corresponding liquid
    cupLiquid.Transparency = 0
end

-- Connect each bottle to addLiquid function
for i = 1, 11 do
    local bottle = script.Parent.Parent:FindFirstChild("Bottle" .. i)
    if bottle then
        local clickDetector = bottle:FindFirstChild("ClickDetector")
        if clickDetector then
            clickDetector.MouseClick:Connect(function()
                addLiquid(i)
            end)
        else
            warn("ClickDetector not found in Bottle" .. i .. ".")
        end
    else
        warn("Bottle" .. i .. " not found.")
    end
end
1 Like

This is a a bad name for this script, because this script handles everything instead of just focusing on doing the cup pickup system. You should be making separate scripts with different purposes (make one script for cup pickup, make another script for adding bottles with the liquid.

Can you possibly show a video of the bug happening?

Sorry if this reply is late but heres a video

but as of now i focused the script on only the pickup of the cup

Also the part where the player touches to receive the cup is CupPickup while the script under it is called PickupScript

-- Script inside the CupPickup Part
local cupPickup = script.Parent
local clickDetector = cupPickup:FindFirstChild("ClickDetector")
local cupModel = game.ReplicatedStorage:FindFirstChild("CupModel")

-- Check if CupModel exists
if not cupModel then
	warn("CupModel not found in ReplicatedStorage.")
	return
end

local function onClicked(player)
	-- Check if the player has a Backpack
	local backpack = player:FindFirstChild("Backpack")
	if not backpack then
		warn("Backpack not found for " .. player.Name .. ".")
		return
	end

	-- Check if the player already has a cup
	if backpack:FindFirstChild("Cup") then
		print("Player " .. player.Name .. " already has a cup.")
		return
	end

	-- Clone the cup tool from ReplicatedStorage and put it in the player's inventory
	local cupTool = cupModel:Clone()
	if not cupTool then
		warn("Failed to clone CupModel.")
		return
	end

	-- Add cup to player's inventory
	cupTool.Parent = backpack
	print("Cup added to inventory for " .. player.Name .. ".")
end

if clickDetector then
	clickDetector.MouseClick:Connect(onClicked)
else
	warn("ClickDetector not found in CupPickup.")
end

That seems to be an issue with the model, not the script. Here are some possible issues:

  • The tool might not have a “Handle” part
  • The tool isn’t welded correctly

it has a handle but also how do i wield it correctly? or know that it is

You need to weld each part to the Handle individually, just create a WeldConstraint for each part and set the Part0 property to the part and the Part1 property to the Handle.

the parts being the liquid correct?

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