Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local tool = script.Parent
- local handle = tool:WaitForChild("Handle")
- local pickedUp = false
- local touchConn
- local function playerHasKey(player)
- local backpack = player:FindFirstChild("Backpack")
- local character = player.Character
- if backpack and backpack:FindFirstChild(tool.Name) then
- return true
- end
- if character and character:FindFirstChild(tool.Name) then
- return true
- end
- return false
- end
- local function onTouched(hit)
- if pickedUp then
- return
- end
- local character = hit.Parent
- if not character then
- return
- end
- local humanoid = character:FindFirstChildOfClass("Humanoid")
- if not humanoid then
- return
- end
- local player = Players:GetPlayerFromCharacter(character)
- if not player then
- return
- end
- pickedUp = true
- if touchConn then
- touchConn:Disconnect()
- end
- if playerHasKey(player) then
- tool:Destroy()
- return
- end
- tool.Parent = player:WaitForChild("Backpack")
- script:Destroy()
- end
- touchConn = handle.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment