Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an item that will give it to you if you click on it and again?

Asked by 5 years ago
Edited 5 years ago

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) ` ~~~~~~~~~~~~~~~~~

0
Put it inside the code block next time Vortex_Vasne 89 — 5y
0
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 Robowon1 323 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)

0
thank you very much FearlessX96 coolguy57811 2 — 5y
Ad

Answer this question