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

When touched, gear goes into backpack?

Asked by
Jxdenx 45
8 years ago
01local Part = script.Parent
02local Tool = game.Lighting.GravityCoil
03local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
04local Debounce = false
05 
06if Tool and Part then
07Part.Touched:connect(function(Part)
08local Humanoid = Part.Parent.Parent.Parent.Parent.Parent.Parent:FindFirstChild('Humanoid')
09if Humanoid and Debounce == false then
10Debounce = true
11local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
12if Player then
13local ClonedTool = Tool:Clone()
14ClonedTool.Parent = Player.Backpack
15wait(10)
View all 21 lines...

Error:

0
https://gyazo.com/27c0c43579818ff2e79035334d016f31 < Image didn't show up for some reason Jxdenx 45 — 8y

1 answer

Log in to vote
0
Answered by
jtefurd 50
8 years ago
01local part = script.Parent;
02local tool = game:GetService("ServerStorage"):FindFirstChild("GravityCoil"); -- Move your gravity coil to Server storage, it doesn't belong in lighting.
03local debounce = true;
04 
05if (tool) then
06    part.Touched:connect(function(touchee)
07        local player = game:GetService("Players"):GetPlayerFromCharacter(touchee.Parent);
08        if (player and debounce) then
09            tool:Clone().Parent = player.Backpack;
10            debounce = false;
11            wait(10);
12            debounce = true;
13        end
14    end)
15end
Ad

Answer this question