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) ` ~~~~~~~~~~~~~~~~~
When you cloned your tool you didn't specify where you should put the tool, you should've called the parameter in the clicked function(i think it's called arguments), on line 26 of your script if you check it I believe. It's hard to pinpoint the exact line of your script since you didn't put your entire code in the code block. Also according to your code you only want to clone 1 tool, which is called "Toast", this is an inefficient way of using arrays. If the code below me does not work feel free to comment about it.
local click = script.Parent.ClickDetector local weaponname = ("Toast") -- PUT TOAST IN LIGHTING // this is assuming you only want 1 tool because I only see 1 tool in that array you made local e = false local time = 2 -- how much seconds you want it to clone to the player's backpack click.MouseClick:Connect(function(player) if e == false and game.Lighting:FindFirstChild(weaponname) then local weaponfr = game.Lighting:FindFirstChild(weaponname):Clone() weaponfr.Parent = player.Backpack e = true wait(time) e = false end end)