Hi everyone. Recently I have been making an airport lounge for my airline, and I want to make it good as people are paying for it, so I have been trying to make food you can pick up by clicking on it. I have tried many ways to do this. Some ways worked, but when someone clicks on the food they will get but if you click on it again it won't give you anything. I have been trying to figure this out for the past couple of days but still have no solution.
Here is the code that I found worked the best:
`local ToolNames = {"Toast"} -- Tool names
local Storage = game:GetService("ServerStorage") -- Tool storage
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
ClickDetector.MouseClick:connect(function(Player)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local already = Player.Backpack:FindFirstChild(ToolNames[i])
if already == nil then
Tool:clone().Parent = Backpack
end
end
end
end
end) `

2 comments
Put it inside the code block next time
You're checking if the tool is already nil in the backpack(nil means non-existent) the first time you take it, there is no tool already so you get it, but after that the tool isn't nil so it won't give it to you