Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When touched, gear goes into backpack?

local Part = script.Parent
local Tool = game.Lighting.GravityCoil
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
local Debounce = false

if Tool and Part then
Part.Touched:connect(function(Part)
local Humanoid = Part.Parent.Parent.Parent.Parent.Parent.Parent:FindFirstChild('Humanoid')
if Humanoid and Debounce == false then
Debounce = true
local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if Player then
local ClonedTool = Tool:Clone()
ClonedTool.Parent = Player.Backpack
wait(10)
end
wait()
Debounce = false
end
end)
end

Error:

1 comment

0

https://gyazo.com/27c0c43579818ff2e79035334d016f31 < Image didn't show up for some reason

1 answer

✓ Accepted answer
local part = script.Parent;
local tool = game:GetService("ServerStorage"):FindFirstChild("GravityCoil"); -- Move your gravity coil to Server storage, it doesn't belong in lighting.
local debounce = true;

if (tool) then
	part.Touched:connect(function(touchee)
		local player = game:GetService("Players"):GetPlayerFromCharacter(touchee.Parent);
		if (player and debounce) then
			tool:Clone().Parent = player.Backpack;
			debounce = false;
			wait(10);
			debounce = true;
		end
	end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.