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

What Script do I use to touch a brick to give me a gear?

Asked by 10 years ago

I have been trying the old script

local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.Backpack

wait(2)
debounce = false
end
end


script.Parent.Parent.Touched:connect(onTouch) 

This is the one that doesn't work.

So I tried fixing it but it still didn't work. Can you help me?

1 answer

Log in to vote
3
Answered by 10 years ago
local partToTouch = Workspace.Part
local toolToGive = Game.ServerStorage.toolName

partToTouch.Touched:connect(function(potentialPlayer)
    if potentialPlayer and potentialPlayer.Parent and Game.Players:GetPlayerFromCharacter(potentialPlayer.Parent) then --Safety first
        local provenPlayer = Game.Players:GetPlayerFromCharacter(potentialPlayer.Parent)
        if not provenPlayer.Backpack:FindFirstChild(toolToGive.Name) then
            toolToGive:Clone().Parent = provenPlayer.Backpack
        end
    end
end
Ad

Answer this question