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
7 years ago
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:

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

1 answer

Log in to vote
0
Answered by
jtefurd 50
7 years ago
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
Ad

Answer this question