Click Detectors and Infinite Storing

I am currently making a game and I made some Lays Classic Chips. The downside is that I don’t know how to use the click detector and script it so instead of climbing on it I can just click it. Here is a video of what I mean. Video: - YouTube

Another problem is that I don’t know how to keep this crisps on for ever. What I mean is that once you take the crisps its gone and you have to re-join the game to spawn it again. Could someone teach me the click detector way by clicking on the crisps instead of touching it and how to script it and how to keep crisps forever so when you take it its still there for the next person.

Thank you.

Using click detectors are very simple.
Insert it into a part that you want to make clickable by the player. After that in a script you can reference the click detector.

local myClickDetector = script.Parent -- replace this to where ever is the actual click detector
myClickDetector.MouseClick:Connect(function(playerWhoClickedIt)
  print(playerWhoClickedIt.Name)
end)

In your case how you could do it, is to copy the chips’ mesh, and put it on the shelf. That will act as a fake copy of it.
After that insert a script in it, and a click detector.
After that, put the original chips (tool) into replicated storage.

Your script should look something like this:

local myClickDetector = script.Parent.ClickDetector
local myChipsTool = game.ReplicatedStorage.Chips -- replace this to the tool's name
myClickDetector.MouseClick:Connect(function(playerWhoClickedIt)
  local backpack = playerWhoClickedIt.Backpack
  myChipsTool:Clone().Parent = backpack
end)

(The scripts are just for demonstrating, not sure if they actually work)
Hope this helped!

1 Like

I would use the script but before I use it I have a Problem. I forgot which part of the script controls the grabbing it when touching it. If I try your script It may glitch out and be confused with ClickDetector or Touching it (I don’t have InsertTouch but it still happens without it).

My script:

local Tool = script.Parent;

enabled = true

function onActivated()
if not enabled then
return
end

enabled = false
Tool.GripForward = Vector3.new(0.675, -0.675, -0.3)
Tool.GripPos = Vector3.new(0.4, -0.9, 0.9)
Tool.GripRight = Vector3.new(0.212, -0.212, 0.954)
Tool.GripUp = Vector3.new(0.707, 0.707, 0)

Tool.Handle.DrinkSound:Play()

wait(.8)

local h = Tool.Parent:FindFirstChild(“Humanoid”)
if (h ~= nil) then
if (h.MaxHealth > h.Health + 1.6) then
h.Health = h.Health + 1.6
else
h.Health = h.MaxHealth
end
end

Tool.GripForward = Vector3.new(-1, 0, 0)
Tool.GripPos = Vector3.new(.2, 0, 0)
Tool.GripRight = Vector3.new(0, 0, -1)
Tool.GripUp = Vector3.new(0,1,0)

enabled = true

end

function onEquipped()
Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Could you please help which part is causing the humanoid to touch and grab the crisps so I could delete the bit and try your script?

Roblox does that automatically for you. If a humanoid touches a tool, it will automatically place it into the backpack.
And your script can stay like that, since in my previous post, that other script will clone the tool, into the backpack of the player, resulting that the script will get copied too.

1 Like

Yes get what you mean when you play the game before you pick it up it puts the InsertTouch:

. The Click Detector thing works which is great but the clone I don’t really understand. I might put another sepertate post but for now thank you for solving the click detector thing.

Yep, fixed the TouchInterert thing, I made another post and a lot of helpful people tried to find the reason until one of them said to turn off CanTouch in the handle so yeah I can now just click on the crisps instead of it automatically adding TouchInterest and annoyingly picking it up when walking through it. But I would like to thank you help though.

The Post: [SOLVED] Cloning Tool and Stop adding TouchInsert