I want it so the object named Cup once clicked goes into the players inventory
The issue is that when i click the Cup model nothing happens and the item doesn’t go into the inventory
I’ve tried looking up online and rewriting the code twice but nothing seems to work
Heres the code i have at the moment the cups script and the inventory script:
local cup = script.Parent
local clickDetector = cup:FindFirstChild("ClickDetector")
local function onClicked(player)
local backpack = player:FindFirstChild("Backpack")
if backpack then
local cupClone = cup:Clone()
cupClone.Parent = backpack
cupClone.Name = "Cup"
cupClone.Anchored = false
cupClone.CanCollide = false
cup:Destroy()
end
end
clickDetector.MouseClick:Connect(onClicked)
local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local function showInventory()
for _, item in pairs(backpack:GetChildren()) do
print("Inventory Item: " .. item.Name)
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.I then
showInventory()
end
end)
I wouldn’t give the player a tool locally. You can make a tool and then insert the model into that… simply rename the man part of it to Handle and make that the primary part of the tool. Then weld the stuff together. Boom. Got a tool.
I’d suggest watching basic tutorials before posting on the forum… there’s many videos that show how to make tools, where to store them, how to use them, make custom ones, etc.
2 cup models, 1 item, 1 model that the player can click to get into their inventory, Alternatively you could just use roblox’s default pick up system and just put the tool on the ground then when the player touches it it goes into their inventory.
As I said, just make a tool in replicated storage, copy and paste whatever is inside the cup expect the script, then change your script to clone the cup from replicated storage, Another issue with your code if this did work was that the cup would have the script in it so other players could click the cup in another players hand and get it.
Also when reading your code, you print the players items when they try to open their inventory, You do know that the player cannot see print(), Right? Print() is just for debugging and outputting information in the console.
Is your Cup a tool or a part? If it’s a part, try this. Parent it to your ClickDetector and create a copy of your tool and put it in ServerStorage.
script.Parent.MouseClick:Connect(function(Player)
local Cup = game:GetService("ServerStorage"):FindFirstChild("Cup"):Clone()
tool.Parent = Player.Backpack
end)
Change your LocalScript to this:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local function ShowInventory()
print("function correctly called")
for _, item in pairs(Character:GetChildren()) do
if item:IsA("Tool") then
print("Inventory item: " .. item.Name)
else
print("No items found :(")
end
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input, GPE)
if not GPE and input.KeyCode == Enum.KeyCode.E then
print("E was clicked")
ShowInventory()
end
end)
where does the first and second code go? also should i convert the model to a tool? also should the one in workspace be model or tool? cuz u only mentioned to dupe it and put in server storage. But im guessing it should be tool in both work space and serverstorage