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