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.
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!
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
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
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.
. 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.